Last active
October 1, 2020 18:41
-
-
Save aal89/8640de0cd2c2667a97d82bb9e2e6bea2 to your computer and use it in GitHub Desktop.
Terminal coloring with git branch if one is found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print_git_data() { | |
if [ $(parse_git_branch) ]; then | |
printf ' (' | |
printf $(parse_git_branch) | |
printf ' ' | |
printf $(parse_latest_commit_hash) | |
printf ')' | |
fi | |
} | |
parse_git_branch() { | |
(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/') | |
} | |
parse_latest_commit_hash() { | |
(git log | grep commit | head -n 1 | awk '{print $2}' | cut -c1-6)2>/dev/null | |
} | |
export PATH="$HOME/.cargo/bin:$PATH" | |
export PS1="\l:\[$(tput sgr0)\]\[$(tput bold)\]\[\033[38;5;10m\]\w\[$(tput sgr0)\]\[$(tput sgr0)\]\[\033[38;5;15m\]\[$(tput bold)\]\[\033[33m\]\$(print_git_data)\[\033[00m\] \[$(tput bold)\]\$?\\$ \[$(tput sgr0)\]" |
The ZSH equivalent:
Also include setopt PROMPT_SUBST
in the .zshrc
.
export PS1='%B%y:%F{green}%~%f%F{yellow}$(print_git_data)%f $ %b'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(old up to rev: 3)