Skip to content

Instantly share code, notes, and snippets.

@xelaz
Created January 27, 2020 09:36
Show Gist options
  • Save xelaz/09b1ddfb052485faa12dd628470262ec to your computer and use it in GitHub Desktop.
Save xelaz/09b1ddfb052485faa12dd628470262ec to your computer and use it in GitHub Desktop.
Zsh prompt with git branch, current node version and .nvmrc version
##### PS1 #######
autoload -U colors && colors
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
check_node() {
diff <(node -v 2> /dev/null) <(cat .nvmrc 2> /dev/null)| sed -e "/^[^>*]/d" -e 's/>.* \(.*\)/ (\1)/'
}
current_node() {
node -v 2> /dev/null | sed 's/\(.*\)/ (\1)/'
}
setopt PROMPT_SUBST
PROMPT='%F{red}%n%f@%F{yellow}%m%f:%F{82}%d%f%F{33}$(parse_git_branch)%f%F{159}$(current_node)%f%F{197}$(check_node)%f
%F{27}%#%f '
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
###################
@xelaz
Copy link
Author

xelaz commented Jan 27, 2020

user@host:cwd (branch) (current nvm version) (needed nvm version if it's not equal with current)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment