Created
June 12, 2018 03:28
-
-
Save nch3ng/407f49c144df79fe73f19b4530ff816b to your computer and use it in GitHub Desktop.
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
ruby_version=`~/.rvm/bin/rvm-prompt v` | |
node_version=`/usr/local/bin/node -v` | |
NONE="\[\033[0m\]" # unsets color to term's fg color | |
# regular colors | |
K="\[\033[0;30m\]" # black | |
R="\[\033[0;31m\]" # red | |
G="\[\033[0;32m\]" # green | |
Y="\[\033[0;33m\]" # yellow | |
B="\[\033[0;34m\]" # blue | |
M="\[\033[0;35m\]" # magenta | |
C="\[\033[0;36m\]" # cyan | |
W="\[\033[0;37m\]" # white | |
# empahsized (bolded) colors | |
EMK="\[\033[1;30m\]" | |
EMR="\[\033[1;31m\]" | |
EMG="\[\033[1;32m\]" | |
EMY="\[\033[1;33m\]" | |
EMB="\[\033[1;34m\]" | |
EMM="\[\033[1;35m\]" | |
EMC="\[\033[1;36m\]" | |
EMW="\[\033[1;37m\]" | |
# background colors | |
BGK="\[\033[40m\]" | |
BGR="\[\033[41m\]" | |
BGG="\[\033[42m\]" | |
BGY="\[\033[43m\]" | |
BGB="\[\033[44m\]" | |
BGM="\[\033[45m\]" | |
BGC="\[\033[46m\]" | |
BGW="\[\033[47m\]" | |
function parse_git_deleted { | |
[[ $(git status 2> /dev/null | grep deleted:) != "" ]] && echo "-" | |
} | |
function parse_git_added { | |
[[ $(git status 2> /dev/null | grep "Untracked files:") != "" ]] && echo '+' | |
} | |
function parse_git_modified { | |
[[ $(git status 2> /dev/null | grep modified:) != "" ]] && echo "*" | |
} | |
function parse_git_dirty { | |
# [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "☠" | |
echo "$(parse_git_added)$(parse_git_modified)$(parse_git_deleted)" | |
} | |
function parse_git_branch { | |
#echo $(parse_git_dirty) | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1 $(parse_git_dirty)/" | |
} | |
function git_name { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/" | |
} | |
function fn_dev_version { | |
if [ -e Gemfile ] | |
then | |
echo " using $R ruby $ruby_version" | |
elif [ -e package.json ] | |
then | |
echo " using $G node $node_version" | |
else | |
echo "" | |
fi | |
} | |
function color_git { | |
if [[ $(git_name) != "" ]] | |
then | |
if [[ $(git_name) == "master" ]] | |
then | |
COLOR=$EMC | |
else | |
COLOR=$EMR | |
fi | |
if [[ $(parse_git_dirty) == "" ]] | |
then | |
echo "($COLOR$(git_name)$NONE)" | |
else | |
echo "($COLOR$(git_name) $EMG$(parse_git_added)$EMY$(parse_git_modified)$EMR$(parse_git_deleted)$NONE)" | |
fi | |
fi | |
} | |
function prompt { | |
if [[ $? = "0" ]]; then RET=$G; else RET=$R; fi; | |
SYM=$'\xE2\x98\x85' | |
BEGIN=$'\xE2\x86\x92' | |
PS1="$EMR$BEGIN \[\033[01;32m\]${C9_USER}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[1;36m\] $NONE$(color_git)$NONE$(fn_dev_version)\[\033[38;5;15m\] $EMY$SYM $NONE " | |
} | |
PROMPT_COMMAND=prompt | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
;; | |
*) | |
;; | |
esac | |
export rvm_silence_path_mismatch_check_flag=1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment