I stumble across all sorts of things when I browse the web late at night after my wife has gone to sleep. Last Monday night, I ran across Oh My Zsh, which is a framework for doing all sorts of things with your Z Shell prompt…and, being a bash bigot, I thought “Hey, I ought to be able to do that in bash!”. I was especially taken by all the git repository information that could be displayed in the prompt, so I went looking and I found https://github.com/magicmonty/bash-git-prompt, which did pretty much the same thing for bash, but without all the fancy angled edges:
Now, this was nice, but you’ll note that the pathname for your current directory appears twice: once in your prompt, and once in your titlebar. I’ve already been putting information in my titlebar for yearsand I didn’t really want to duplicate information. So I started looking at how to customize this bash git prompt.
Fortunately, there’s a whole section on configuration in the documentation, and, with just a little tweaking
# This theme for gitprompt.sh is optimized for the # "Solarized Dark" and "Solarized Light" color schemes # tweaked for Ubuntu terminal fonts override_git_prompt_colors() { GIT_PROMPT_THEME=Custom GIT_PROMPT_LEADING_SPACE=0 GIT_PROMPT_PREFIX= "" GIT_PROMPT_SUFFIX= "" GIT_PROMPT_THEME_NAME= "Solarized" GIT_PROMPT_STAGED= "${Yellow}●" GIT_PROMPT_CHANGED= "${BoldBlue}∆" # delta means change! GIT_PROMPT_STASHED= "${BoldMagenta}⚑ " GIT_PROMPT_CLEAN= "${Green}<img draggable=" false " role=" img " class=" emoji " alt="
" src=" https: //s .w.org /images/core/emoji/15 .0.3 /svg/2714 .svg ">" GIT_PROMPT_BRANCH= "${Yellow}" GIT_PROMPT_END_COMMON= "_LAST_COMMAND_INDICATOR_ ${BoldBlue}${Time12a}${ResetColor}" GIT_PROMPT_END_USER= "\n${GIT_PROMPT_END_COMMON} $ " GIT_PROMPT_END_ROOT= "\n${GIT_PROMPT_END_COMMON} # " GIT_PROMPT_START= "\[\e]0;\u@\h: \w\007\]" PROMPT_START= "\[\e]0;\u@\h: \w\007\]" PROMPT_END= "${GIT_PROMPT_END_COMMON} $ " } reload_git_prompt_colors "Solarized" |
I was able to turn my bash prompt into something a little more useful when I’m coding!