News for hackers. Stuff that matters.
Re:Interesting Bash Prompts by tlrobinson on Sunday September 06, 2009 @04:52AM (#807613)
+1 for the git branch.

Here's my bash prompt script. It shows the command number from this session (PS_NUM), the exit code of the last command (highlighted red if != 0), the pwd (in cyan), and the git branch (in magenta)

    OFF="\[\033[0m\]"
    RED="\[\033[0;31m\]"
    MAGENTA="\[\033[0;35m\]"
    CYAN="\[\033[0;36m\]"

    function promptcommand {
        STATUS=$?
    
        PS_NUM="[\#]"
        PS_STATUS="[$STATUS]"
        PS_PWD="${CYAN}\w${OFF}"
        PS_GITBRANCH="${MAGENTA}\$(__git_ps1)${OFF}"
        PS_PROMPT="\$"
    
        if [ $STATUS -ne "0" ]; then
            PS_PROMPT="${RED}${PS_PROMPT}${OFF}"
        fi
    
        PS1="${PS_NUM}${PS_STATUS} ${PS_PWD}${PS_GITBRANCH} ${PS_PROMPT} "
    }
    PROMPT_COMMAND=promptcommand
I probably could have eliminated the PROMPT_COMMAND thing like in the first example.

There are no comments on this comment yet.