Skip to content

Instantly share code, notes, and snippets.

@sagax
Last active January 17, 2019 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagax/76c3855e68cd11e3fd8e41653322eca0 to your computer and use it in GitHub Desktop.
Save sagax/76c3855e68cd11e3fd8e41653322eca0 to your computer and use it in GitHub Desktop.
bashrc ps1 with git
export TERM="xterm-256color"
export EDITOR="vim"
# source link:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
#
# download link:
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
PATHTOGITPROMPT="$HOME/git-prompt.sh"
[[ -s "$PATHTOGITPROMPT" ]] && source "$PATHTOGITPROMPT"
c_off="\[\e[0m\]"
c_bold_on="\[\e[1m\]"
c_light_on="\[\e[2m\]"
c_underscore="\[\e[4m\]"
c_blink_on="\[\e[5m\]"
c_reverse="\[\e[7m\]"
c_concealed_on="\[\e[8m\]"
c_f_blue="\[\e[34m\]"
c_f_red="\[\e[38;2;255;0;0m\]"
c_f_green="\[\e[38;2;0;255;0m\]"
c_f_white="\[\e[38;2;255;255;255m\]"
c_f_gray="\[\e[38;2;128;128;128m\]"
c_f_slate_gray="\[\e[38;2;112;128;144m\]"
c_f_dodger_blue="\[\e[38;2;30;144;255m\]"
c_f_light_steel_blue="\[\e[38;2;176;196;222m\]"
c_f_lime_green="\[\e[38;2;50;205;50m\]"
symbol1="\xE2\x97\x88"
symbol2="\xE2\x9D\xAF"
__ps1() {
printf "%s%s%s%s %s %s%s%s %s " \
$(if [[ $(whoami) == "root" ]]; then printf "%b%b%s%b" "$c_bold_on" "$c_f_red" "\u" "$c_off"; else printf "%b%b%s%b" "$c_bold_on" "$c_f_blue" "\u" "$c_off"; fi) \
$(printf "%b%b%b%b" "$c_light_on" "$c_f_light_steel_blue" "$symbol1" "$c_off") \
$(printf "%b%b%s%b" "$c_bold_on" "$c_f_dodger_blue" "\h" "$c_off") \
$(if [[ -n $(declare -f -F "__git_ps1" 2>/dev/null) ]]; then printf "%b%b%s%b" "$c_bold_on" "$c_f_lime_green" "\$(__git_ps1)" "$c_off"; else printf ""; fi) \
$(printf "%b%b%s%b" "$c_bold_on" "$c_f_slate_gray" "\t" "$c_off") \
$(printf "%b%b%s%b" "$c_bold_on" "$c_f_gray" "\w" "$c_off") \
"\n" \
"\$(if test \$? -eq 0; then printf \"%b%b%b\" \"$c_f_green\" \"\\\xE2\\\x96\\\xA3\" \"$c_off\"; else printf \"%b%b%b\" \"$c_f_red\" \"\\\xE2\\\x96\\\xA3\" \"$c_off\"; fi)" \
$(if [[ $(whoami) == "root" ]]; then printf "%b%b%b%b" "$c_bold_on" "$c_f_red" "$symbol2" "$c_off"; else printf "%b%b%b" "$c_f_white" "$symbol2" "$c_off"; fi)
}
PS1="$(__ps1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment