Skip to content

Instantly share code, notes, and snippets.

@nyrahul
Created January 11, 2018 07:41
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 nyrahul/919cd69d2ccece93e24ce18742dc77c3 to your computer and use it in GitHub Desktop.
Save nyrahul/919cd69d2ccece93e24ce18742dc77c3 to your computer and use it in GitHub Desktop.
Set netns name and git branch name in bash-PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
netns_name() {
str=`ip netns identify $$`
[[ "$str" != "" ]] && echo "\033[1;35m[$str]\033[0m " && return
}
export PS1="$(netns_name)\u@\h:\[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment