Skip to content

Instantly share code, notes, and snippets.

@aal89

aal89/profile

Last active Oct 1, 2020
Embed
What would you like to do?
Terminal coloring with git branch if one is found
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)\]"
@aal89

This comment has been minimized.

Copy link
Owner Author

@aal89 aal89 commented Jan 3, 2020

image
(old up to rev: 3)

@aal89

This comment has been minimized.

Copy link
Owner Author

@aal89 aal89 commented Jan 9, 2020

image
(from rev: 3 and up)

@aal89

This comment has been minimized.

Copy link
Owner Author

@aal89 aal89 commented Aug 4, 2020

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
You can’t perform that action at this time.