Created
May 2, 2019 18:50
-
-
Save adamweeks/418007199556cd08fc7457c653b3b8fe to your computer and use it in GitHub Desktop.
Bash prompt that shows current node version and git status
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
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