Skip to content

Instantly share code, notes, and snippets.

@dmcquillan314
Created March 17, 2016 14:12
Show Gist options
  • Save dmcquillan314/f05a49f548ae453b7547 to your computer and use it in GitHub Desktop.
Save dmcquillan314/f05a49f548ae453b7547 to your computer and use it in GitHub Desktop.
PS1 configuration with version control information
## Print nickname for git/hg/bzr/svn version control in CWD
## Optional $1 of format string for printf, default "(%s) "
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
}
get_styled_version_ctl_branch() {
CUR_BRANCH=$(get_version_ctl_branch "$1")
if [[ "${CUR_BRANCH}" =~ ^.*(master).*$ ]]; then
printf "\033[38;5;257m${CUR_BRANCH}\033[00m"
else
printf "\033[38;5;173m${CUR_BRANCH}\033[00m"
fi
}
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
#PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[0;35;49m\]\$(parse_git_branch)\[\033[00m\n\033[38;5;173mλ\033[0;00m \]"
PS1_UN="\[\033[38;5;260m\]\u@\h\[\033[00m\]"
PS1_DIR="\[\033[38;5;4m\]\w\[\033[00m\]"
PS1_GIT_CUR="\[\033[38;5;173m\]\$(get_version_ctl_branch "$2")\[\033[00m\]"
PS1_MASTER_GIT_CUR="\[\033[38;5;257m\]\$(get_version_ctl_branch "$2")\[\033[00m\]"
PS1_VERSION_CTL="\$(get_styled_version_ctl_branch "$2")"
get_symbol() {
CUR_DATE=$(date +'%m%d')
if [ $CUR_DATE -eq "0314" ]; then
printf "$PS1_PI"
elif [ $CUR_DATE -eq "0628" ]; then
printf "$PS1_2PI"
elif [ $CUR_DATE -eq "0317" ]; then
printf "$PS1_SHAMROCK"
elif [ $CUR_DATE -eq "1031" ]; then
printf "$PS1_HALLOWEEN"
elif [ $CUR_DATE -eq "1224" ]; then
printf "$PS1_XMAS"
elif [ $CUR_DATE -eq "1225" ]; then
printf "$PS1_XMAS"
else
printf "$PS1_LAMBDA"
fi
}
PS1_LAMBDA="λ"
PS1_PI="Π"
PS1_2PI="2Π"
PS1_ZETA="ζ"
PS1_SHAMROCK="☘ "
PS1_XMAS="🎄 "
PS1_HALLOWEEN="🎃 "
PS1_SYMBOLS="\[\033[38;5;173m\]\$(get_symbol)\[\033[0;00m\]"
PS1="${debian_chroot:+($debian_chroot)}${PS1_UN}:${PS1_DIR} ${PS1_VERSION_CTL}\n${PS1_SYMBOLS} " #\[$(tput sgr0)\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment