Thatbytes

Mostly Interesting

Updated Fun With Bash Prompts

After working with my prompt for a few months I thought it only fixing to update my post with the changes I have made.

The update configuration is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function _git_prompt() {
  local git_status="`git status -unormal 2>&1`"
    if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
      if [[ "$git_status" =~ nothing\ to\ commit ]]; then
        local ansi=32
          elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
          local ansi=31
      else
        local ansi=33
          fi
          echo -n '\[\e[0;33;'"$ansi"'m\]'"$(__git_ps1)"'\[\e[0m\]'
          fi
}
function _prompt_command() {
  PS1="`if [ \$? = 0 ]; then echo -n '\[\e[0;33;32m\]^-^';else echo -n '\[\e[0;33;31m\]-_-';fi`\[\033[00m\] \u@\h \[\033[36m\]\w `_git_prompt`\[\033[37m\]$\[\033[00m\]"
}
PROMPT_COMMAND=_prompt_command

Comments