3 ms·
+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
by tlrobinson 17y ago
+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.