Basic Linux and Application Configuration Locate to ~/.config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
2.3 KiB

# vim: ft=sh
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "${PC}(${GC}${BRANCH}${STAT}${PC})"
else
echo ""
fi
}
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
# Colours
DEFAULT="\[\033[0;0m\]"
default="\[\033[0;1m\]"
# Colours
# 1red 2green 3brown 4blue 5purple 6cyan 7green
RED="\[\033[0;31m\]"
BLU="\[\033[0;34m\]"
PNK="\[\033[0;31m\]"
YLW="\[\033[0;33m\]"
GRN="\[\033[0;32m\]"
LIM="\[\033[0;32m\]"
GRY="\[\033[0;31m\]"
CYN="\[\033[0;36m\]"
PC=$DEFAULT # Punctuation colour
# Root user appears red, others blue
if [[ $USER == 'root' ]]; then
UC=$RED # User colour
else
UC=$GRN
fi
# If SSH, host appears _, local green
if [[ $SSH_TTY != '' ]]; then
HC="${YLW}" # Host colour
else
HC="${BLU}"
fi
# If git repo, path appears in _, otherwise _
GC="\[\033[0;35m\]"
GIT=$(parse_git_branch)
if [[ $GIT == '' ]]; then
W="${GRY}\w"
else
W="${CYN}\w${GIT}"
fi
# Line beginning and ending if wrapped
if [ $(($(($(tput cols)-$(pwd|sed -e "s/\/home\/.*\/?/~/g"|wc -c))) < 90 )) == 1 ];then
BEGINNING="┌["
ENDING="]\n└"
else
BEGINNING=""
ENDING=""
fi
export PS1="\a${debian_chroot:+($debian_chroot)}${PC}${BEGINNING}${UC}\u${PC}@${HC}\h${PC}:${CYN}\w${GIT}${PC}${ENDING}${DEFAULT}"