Created
April 11, 2016 13:53
-
-
Save jensens/616ead9bcd68051647a721195510bafe to your computer and use it in GitHub Desktop.
my colorful git aware prompt with abbreviations for workspace
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
# Regular | |
txtblk="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black | |
txtred="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red | |
txtgrn="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green | |
txtylw="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow | |
txtblu="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue | |
txtpur="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple | |
txtcyn="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan | |
txtwht="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White | |
# Bold | |
bldblk="$(tput setaf 0 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;30m')" # Black | |
bldred="$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;31m')" # Red | |
bldgrn="$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;32m')" # Green | |
bldylw="$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;33m')" # Yellow | |
bldblu="$(tput setaf 4 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;34m')" # Blue | |
bldpur="$(tput setaf 5 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;35m')" # Purple | |
bldcyn="$(tput setaf 6 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;36m')" # Cyan | |
bldwht="$(tput setaf 7 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;37m')" # White | |
# Underline | |
undblk="$(tput setaf 0 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;30m')" # Black | |
undred="$(tput setaf 1 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;31m')" # Red | |
undgrn="$(tput setaf 2 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;32m')" # Green | |
undylw="$(tput setaf 3 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;33m')" # Yellow | |
undblu="$(tput setaf 4 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;34m')" # Blue | |
undpur="$(tput setaf 5 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;35m')" # Purple | |
undcyn="$(tput setaf 6 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;36m')" # Cyan | |
undwht="$(tput setaf 7 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;37m')" # White | |
# Background | |
bakblk="$(tput setab 0 2>/dev/null || echo '\e[40m')" # Black | |
bakred="$(tput setab 1 2>/dev/null || echo '\e[41m')" # Red | |
bakgrn="$(tput setab 2 2>/dev/null || echo '\e[42m')" # Green | |
bakylw="$(tput setab 3 2>/dev/null || echo '\e[43m')" # Yellow | |
bakblu="$(tput setab 4 2>/dev/null || echo '\e[44m')" # Blue | |
bakpur="$(tput setab 5 2>/dev/null || echo '\e[45m')" # Purple | |
bakcyn="$(tput setab 6 2>/dev/null || echo '\e[46m')" # Cyan | |
bakwht="$(tput setab 7 2>/dev/null || echo '\e[47m')" # White | |
# Reset | |
txtrst="$(tput sgr 0 2>/dev/null || echo '\e[0m')" # Text Reset |
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
function git_prompt() { | |
# Based on: http://stackoverflow.com/a/13003854/170413 | |
local branch | |
local dirty | |
local status=$(git status --porcelain 2> /dev/null) | |
if [[ "$status" != "" ]]; then | |
dirty='*' | |
else | |
dirty='' | |
fi | |
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then | |
if [[ "$branch" == "HEAD" ]]; then | |
branch='detached*' | |
fi | |
printf "($branch$dirty)" | |
fi | |
} |
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
function short_cwd() { | |
cwd=`pwd` | |
cwd="${cwd/\/home\/workspacejensens/\~w}" | |
cwd="${cwd/\/home\/jensens\/workspace/\~w}" | |
cwd="${cwd/\/home\/jensens/\~}" | |
printf $cwd | |
} |
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
... snip ... | |
export BASHSRC=~/.bash | |
source "$BASHSRC/git-aware-prompt/colors.sh" | |
source "$BASHSRC/git-aware-prompt/prompt.sh" | |
source "$BASHSRC/shortcwd.sh" | |
PS1="\[$bldblu\]\$(short_cwd)\[$txtrst\]\[$txtblu\]\$(git_prompt)\[$txtgrn\]$ \[$txtrst\]" | |
... snip ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment