Skip to content

Instantly share code, notes, and snippets.

@jvz
Created February 24, 2017 03:47
Show Gist options
  • Save jvz/6b5ca8f38527fb2b06b08c493c0d81d0 to your computer and use it in GitHub Desktop.
Save jvz/6b5ca8f38527fb2b06b08c493c0d81d0 to your computer and use it in GitHub Desktop.
if [[ ! -f ~/.git-prompt.sh ]]; then
curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
fi
. ~/.git-prompt.sh
function get_version_ctl_branch() {
local dir="$PWD"
local vcs
local nick
while [[ "$dir" != "/" ]]; do
for vcs in git hg svn bzr; do
if [[ -d "$dir/.$vcs" ]] && hash "$vcs" &>/dev/null; then
case "$vcs" in
git) __git_ps1 "${1:-(%s) }"; return;;
hg) nick=$(hg branch 2>dev/null);;
svn) nick=$(svn info 2>/dev/null\
| grep -e '^Repository Root:'\
| sed -e 's#.*/##');;
bzr)
local conf="${dir}/.bzr/branch/branch.conf"
[[ -f "$conf" ]] && nick=$(grep -E '^nickname =' "$conf" | cut -d' ' -f 3)
conf="${dir}/.bzr/branch/location" # colo/lightweight branch
[[ -z "$nick" ]] && [[ -f "$conf" ]] && nick="$(basename "$(< $conf)")"
[[ -z "$nick" ]] && nick="$(basename "$(readlink -f "$dir")")";;
esac
[[ -n "$nick" ]] && printf "${1:-(%s) }" "$nick"
return 0
fi
done
dir="$(dirname "$dir")"
done
}
PS1_UN="\[\033[38;5;33m\]\u@\h\[\033[00m\]"
PS1_DIR="\[\033[38;5;26m\]\w\[\033[00m\]"
PS1_GIT_CUR="\[\033[0;35;49m\]\$(get_version_ctl_branch "$2")\[\033[00m\]"
PS1_LAMBDA="\[\033[38;5;173m\]λ\[\033[0;00m\]"
PS1="${PS1_UN}:${PS1_DIR} ${PS1_GIT_CUR}\n${PS1_LAMBDA} \[$(tput sgr0)\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment