Skip to content

Instantly share code, notes, and snippets.

@swghosh
Created March 1, 2022 07:40
Show Gist options
  • Save swghosh/d13a723cd9ce7f442f58c695f7bbd123 to your computer and use it in GitHub Desktop.
Save swghosh/d13a723cd9ce7f442f58c695f7bbd123 to your computer and use it in GitHub Desktop.
Slightly colored terminal prompt with vcs information.
#!/usr/bin/env bash
export COLOR_NC='\e[0m' # No Color
export COLOR_BLACK='\e[0;30m'
export COLOR_GRAY='\e[1;30m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export COLOR_WHITE='\e[1;37m'
if [ -z "$PS1" ]; then
return
fi
PROMPT_VCS=1 # version control system name, branch and dirty status
prompt.vcs.enable(){
PROMPT_VCS=1
}
prompt.vcs.disable(){
PROMPT_VCS=0
}
vcs(){
[ $PROMPT_VCS -eq "1" ] && echo -e "$(vcprompt -f "%n[%b%m%u]")"
}
bash_prompt() {
PS1="${COLOR_CYAN}\u${COLOR_NC} @ \h \
${COLOR_YELLOW}\w${COLOR_NC}\
$COLOR_BLUE\$(vcs)$COLOR_NC \n→ "
}
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ;}"
bash_prompt

In order to print VCS related information, vcprompt should be installed and available on PATH (before this rc file is sourced).

Adding the following lines to the end of your ~/.bashrc file should modify the bash prompt each time.

source ~/.colored_bash_prompt.bashrc

vcprompt can be obtained from https://formulae.brew.sh/formula/vcprompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment