Bash - Set the style of bash prompt used

# @param String $type Allowed values: brief, full, root, compact, basic or files # function set_prompt() { use_color=$2 case "$1" in brief) PS1="\[\e[1;33m\]\u" # username PS1+="\[\e[1;37m\]@" # @ PS1+="\[\e[1;32m\]\h " # host PS1+="\[\e[1;31m\]\W" # base directory name PS1+="\[\e[1;36m\]$(parse_git_branch)\$ \[\e[0m\]" ;; full) # username@machine.local ~/dir # Sat Jan 18 22:37:10 [626]$ PS1="\n" PS1+="\[\033[1;35m\]\W\e[m\n" # /path/to/dir PS1+="\[\033[1;37m\]\u@\h\e[m\n" # username@host.domain.com PS1+="\[\033[1;36m\]\d \t \$(parse_git_branch)\$\e[m " ;; root) PS1="\n" PS1+="\[\033[1;31m\]\u@\h\e[m\n" # username@host PS1+="\[\033[1;37m\]\d \t\e[m\n" # Sat Dec 19 16:23:24 PS1+="\[\033[1;36m\]\w\e[m" # /path/to/dir PS1+=" \$\e[m " ;; compact) PS1="\n" PS1+="\[\033[1;32m\]\u\e[m" PS1+="@" PS1+="\[\033[1;35m\]\h\e[m\n" PS1+="\[\033[1;36m\]\A \W\$(parse_git_branch)\e[m\$ " ;; basic) PS1="\n\u@\h\n\A \W\$ " ;; files) PS1="\n" PS1+="\[\033[1;31m\][\w]\e[m\n" PS1+="\[\033[1;37m\]\u@\h\e[m " PS1+="\[\033[1;36m\](\$(ls -1 | wc -l | sed 's: ::g') files)\e[m\n" PS1+="\$ " ;; *) echo 'Whoops! brief, full, root, compact, basic, or files' ;; esac }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.