Last active
March 8, 2023 17:15
-
-
Save jerameel/53b0fbad4936352d9c9b9b4eb1760ad5 to your computer and use it in GitHub Desktop.
Custom Bash Prompt with Git branch and Node version for NVM support.
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
parse_git_branch() { | |
OUT=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | |
if [ -n "$OUT" ]; then | |
echo $OUT | |
else | |
echo 'N/A' | |
fi | |
} | |
parse_node_version(){ | |
OUT=$(node --version 2> /dev/null) | |
if [ -n "$OUT" ]; then | |
echo $OUT | |
else | |
echo 'N/A' | |
fi | |
} | |
PS1_DATE='\[\e[0;38;5;220m\]\T' | |
PS1_USER='\[\e[0;38;5;45m\]\u\[\e[0m\]' | |
PS1_HOSTNAME='\[\e[0;37m\]\h' | |
PS1_WD='\[\e[0m\][\[\e[0;38;5;220m\]\w\[\e[0m\]]' | |
PS1_NODE='\[\e[0;38;5;253m\]node: \[\e[0;38;5;196m\]$(parse_node_version)' | |
PS1_GIT='\[\e[0;38;5;253m\]branch: \[\e[0;38;5;196m\]$(parse_git_branch)' | |
PS1_PROMPT='[\[\e[0;38;5;45m\]\$\[\e[0m\]] ->' | |
export PS1='| '$PS1_DATE' '$PS1_USER'@'$PS1_HOSTNAME' '$PS1_WD'\n|-- '$PS1_NODE'\[\e[0m\] - '$PS1_GIT' \n\[\e[0m\]| '$PS1_PROMPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment