Skip to content

Instantly share code, notes, and snippets.

@pyncc
Created March 23, 2018 22:01
Show Gist options
  • Save pyncc/89c68f092378343361612f93b00f9d59 to your computer and use it in GitHub Desktop.
Save pyncc/89c68f092378343361612f93b00f9d59 to your computer and use it in GitHub Desktop.
my PS1
STAND="$(tput rev)"
RESET="$(tput sgr0)"
git-branch() {
branch=$(git branch 2> /dev/null | grep \* | cut -d' ' -f2)
if [ $branch ];then
if [ ${#branch} -gt 25 ];then
branch="${branch:0:24}…"
fi
echo -e "⑆ $branch"
fi
}
git-drrty() {
git diff 2> /dev/null | head -c 1 | sed 's/d/ʹ/'
}
shell-level() {
if [[ "$SHLVL" > "2" ]];then
echo '◉ '
else
echo '〇'
fi
}
git_stat() {
local _git_stat _git_branch
cr='\n' #܀ #'◿\n' #'␍\xCC\xB2 \n' #䷗ #〇 #● #"䷗" # ␍
_git_branch=$(git-branch)
if [[ "$_git_branch" ]];then
_git_stat="$_git_branch$(git-drrty)"
if [ "$GIT_WORKTREE" ]; then
_git_stat="$cr$_git_stat ᛋ $GIT_WORKTREE "
else
_git_stat="$cr$_git_stat "
fi
else
_git_stat=" "
fi
printf "$_git_stat"
}
short_pwd() {
# because not gnu-sed with 'gN' (g5 to match first 5) flag
pwd | sed 's:\([^/]\)[^/]*/:\1/:; s:\([^/]\)[^/]*/:\1/:2; s:\([^/]\)[^/]*/:\1/:3; s:\([^/]\)[^/]*/:\1/:4; s:\([^/]\)[^/]*/:\1/:5'
#pwd | sed 's:\([^/]\)[^/]*/:\1/:g'
#echo -e '\\W'
}
ret_code() {
local ret
ret=$1
if [ $ret != 0 ];then
printf "${STAND}$ret${RESET} "
fi
#echo "$ret${RESET}"
}
PS1=$'$(ret_code $?)\\t☰ :$(short_pwd)$(git_stat)$(shell-level) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment