We can set up our terminal shell to show the git branch as well by modifying the variable PS1. Your user home directory have a hidden file name .profile (dot profile) which have this variable, you need to tweak it little bit to fit in our ask.
To get which shell you are using, execute below command -
echo $SHELL
If you are using Korn Shell (ksh):
# Setting up PS1 value
export HOST=`hostname -a`
export GIT_BRANCH="$(print "\033[35m (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \033[00m")"export PS1="\${USER}@\${HOST}:\${PWD}${GIT_BRANCH}\$ "
If you are using Bash Shell (bash):
# Setting up PS1 value
parse_git_branch() {git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'}
export PS1="[\u@\h \[\e[32m\]\W \[\e[91m\]\$(parse_git_branch)\[\e[00m\]]$ "
Facebook Page Facebook Group Twitter Feed Telegram Group
No comments:
Post a Comment