Skip to content

Instantly share code, notes, and snippets.

@Keyes
Last active August 28, 2018 06:20
Show Gist options
  • Save Keyes/5c7ffa0f77d05f34615ac7830ea8d74c to your computer and use it in GitHub Desktop.
Save Keyes/5c7ffa0f77d05f34615ac7830ea8d74c to your computer and use it in GitHub Desktop.
Bash prompt including package + version and git branch
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
export NODE_ENV=development
alias l="ls -lisa"
alias gs="grunt serve"
alias gb="grunt build"
alias clone="git clone $1 $2"
alias branch="git branch $1 $2 $3"
gpush() {
git add . &&
git commit -m "$1" &&
git push;
}
export CLICOLOR=1
export LSCOLORS=GxBxCxDxexegedabagaced
parse_git_branch() {
if [ $(git rev-parse --is-inside-work-tree 2> /dev/null) ]; then
STR="$(git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1/')"
if [[ ! $( git status --porcelain) ]]; then
STR+=" ✓)"
else
STR+=" *)"
fi
fi
echo -e "$STR"
}
get_packagename() {
echo "$(grep '"name"' ./package.json | grep -o ': ".*"' | cut -d \" -f 2)"
}
get_packageversion() {
echo "$(grep '"version"' ./package.json | grep -o ': ".*"' | cut -d \" -f 2)"
}
get_nodepackage() {
STR=""
if [ -e "./package.json" ]; then
STR+="\033[1;31m"
if [ $(get_packagename) ]; then
STR+=$(get_packagename)
fi
if [[ $(get_packagename) && $(get_packageversion) ]]; then
STR+="@"
fi
if [ $(get_packageversion) ]; then
STR+=$(get_packageversion)
fi
STR+=" "
fi
STR+="\033[0;32m[$(echo "$(node -v)")]"
echo -e $STR
}
export PS1="\$(get_nodepackage)\033[0;33m\$(parse_git_branch) \e[1;34m\w \e[0m$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment