Skip to content

Instantly share code, notes, and snippets.

@adamweeks
Created May 2, 2019 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamweeks/418007199556cd08fc7457c653b3b8fe to your computer and use it in GitHub Desktop.
Save adamweeks/418007199556cd08fc7457c653b3b8fe to your computer and use it in GitHub Desktop.
Bash prompt that shows current node version and git status
RED_COLOR="\[$(tput setaf 1)\]"
YELLOW_COLOR=""
END_COLOR="\[$(tput sgr0)\]"
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo " ↺ "
}
function __git_branch {
__git_ps1 "%s"
}
function __node {
if hash node 2>/dev/null; then
local v=$(node -v)
fi
[ "$v" != "" ] && echo "n:${v:1}"
}
function __info {
local full=(
$(tput setaf 0)$(tput setab 2)$(__node)$(tput sgr0)
$(tput setaf 0)$(tput setab 1)$(__git_branch)$(__git_dirty)$(tput sgr0)
)
full="${full[*]}"
[ "$full" != "" ] && echo "[$full]"
}
PS1="┌─\$(__info)──(\w)
└─> "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment