Skip to content

Instantly share code, notes, and snippets.

@liuderchi
Last active April 18, 2024 21:13
Show Gist options
  • Save liuderchi/ed5c352d5742dbce3961495d04ade990 to your computer and use it in GitHub Desktop.
Save liuderchi/ed5c352d5742dbce3961495d04ade990 to your computer and use it in GitHub Desktop.
Customize Command Prompt Text with Git Icon and Git Branch (require font-awesome)
# README
# 1. append following content to your ~/.bashrc file
# 2. apply your setup by enter shell command $ source ~./bashrc
### Git ###
git_icon() {
# NOTE: printing icon requires install font on http://fontawesome.io/
# Choose one icon you like
#printf ' \uf126 ' # http://fontawesome.io/icon/code-fork/
printf ' \uf09b ' # http://fontawesome.io/icon/github/
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
git_info() {
if [[] $(parse_git_branch) ]]; then
git_icon
parse_git_branch
fi
}
### add Color ANSI code ###
orange='\e[38;5;172m'
atomGreen='\e[38;5;29m'
reverse='\e[7m'
reset=$(tput sgr0) # use color setting in terminal Preference
# get more color on this site: http://misc.flogisoft.com/bash/tip_colors_and_formatting
### Choose One Template for Your PS1 ###
#PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w \$(parse_git_branch) $ " # with user and hostname
#PS1="${debian_chroot:+($debian_chroot)}[\w] \$(parse_git_branch)$ " # no user name and hostname
PS1="${debian_chroot:+($debian_chroot)}\[$orange\]\w\[$atomGreen\]\$(git_info)\[$orange\]❯ " # Light style: with color, special char ❯
#PS1="${debian_chroot:+($debian_chroot)}\[$reverse\]\w \[$atomGreen\]\$(git_info)\[$reset\]\[$orange\]❯ " # Reverse Style: with background color, special char ❯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment