Update git prompt. Include git-prompt.sh in repo
This commit is contained in:
@@ -5,83 +5,102 @@ set_prompt_fancy()
|
||||
local is_git="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
|
||||
|
||||
local last_cmd=$?
|
||||
local txtreset='$(tput sgr0)'
|
||||
local txtrst='$(tput sgr0)'
|
||||
local txtbold='$(tput bold)'
|
||||
local txtblack='$(tput setaf 0)'
|
||||
local txtblk='$(tput setaf 0)'
|
||||
local txtred='$(tput setaf 1)'
|
||||
local txtgreen='$(tput setaf 2)'
|
||||
local txtyellow='$(tput setaf 3)'
|
||||
local txtblue='$(tput setaf 4)'
|
||||
local txtpurple='$(tput setaf 5)'
|
||||
local txtcyan='$(tput setaf 6)'
|
||||
local txtwhite='$(tput setaf 7)'
|
||||
local txtgrn='$(tput setaf 2)'
|
||||
local txtyel='$(tput setaf 3)'
|
||||
local txtblu='$(tput setaf 4)'
|
||||
local txtpur='$(tput setaf 5)'
|
||||
local txtcyn='$(tput setaf 6)'
|
||||
local txtwht='$(tput setaf 7)'
|
||||
# unicode "✗"
|
||||
local fancyx='\342\234\227'
|
||||
# unicode "✓"
|
||||
local checkmark='\342\234\223'
|
||||
# Line 1: Full date + full time (24h)
|
||||
# Line 2: current path
|
||||
PS1="\[$txtbold\]\[$txtwhite\]\n\D{%A %d %B %Y %H:%M:%S}\n\[$txtgreen\]\w\n"
|
||||
PS1="\[$txtbold\]\[$txtwht\]\n\D{%A %d %B %Y %H:%M:%S}\n\[$txtgrn\]\w\n"
|
||||
# Line 3: Git repo + path in repo
|
||||
if [ "$is_git" ]; then
|
||||
local git_repo=$(basename `git rev-parse --show-toplevel` 2>/dev/null)
|
||||
local git_rel_path=$(git rev-parse --show-prefix 2>/dev/null)
|
||||
PS1+="$txtcyan$git_repo $txtpurple$git_rel_path$txtreset\n"
|
||||
PS1+="$txtcyn$git_repo $txtpur$git_rel_path$txtrst\n"
|
||||
fi
|
||||
# User color: red for root, yellow for others
|
||||
# User color: red for root, yel for others
|
||||
if [[ $EUID == 0 ]]; then
|
||||
PS1+="\[$txtred\]"
|
||||
else
|
||||
PS1+="\[$txtyellow\]"
|
||||
PS1+="\[$txtyel\]"
|
||||
fi
|
||||
# Line 3: user@host
|
||||
PS1+="\u\[$txtwhite\]@\h\n"
|
||||
# Line 4: a red "✗" or a green "✓" and the error number
|
||||
PS1+="\u\[$txtwht\]@\h\n"
|
||||
# Line 4: a red "✗" or a grn "✓" and the error number
|
||||
if [[ $last_cmd == 0 ]]; then
|
||||
PS1+="\[$txtgreen\]$checkmark \[$txtwhite\](0)"
|
||||
PS1+="\[$txtgrn\]$checkmark \[$txtwht\](0)"
|
||||
else
|
||||
PS1+="\[$txtred\]$fancyx \[$txtwhite\]($last_cmd)"
|
||||
PS1+="\[$txtred\]$fancyx \[$txtwht\]($last_cmd)"
|
||||
fi
|
||||
# Line 4: green git branch
|
||||
PS1+="\[$txtgreen\]$(__git_ps1 ' (%s)')\[$txtwhite\]"
|
||||
# Line 4: grn git branch
|
||||
PS1+="\[$txtgrn\]$(__git_ps1 ' (%s)')\[$txtwht\]"
|
||||
# Line 4: good old prompt, $ for user, # for root
|
||||
PS1+=" \\$ "
|
||||
}
|
||||
|
||||
format_modified() {
|
||||
local txtrst='$(tput sgr0)'
|
||||
local txtred='\e[0;31m'
|
||||
local txtgrn='$(tput setaf 2)'
|
||||
local txtyel='$(tput setaf 3)'
|
||||
|
||||
# Modified, staged and untracked
|
||||
n_mod=$(git status --porcelain 2>/dev/null| grep "^ M" | wc -l)
|
||||
n_sta=$(git status --porcelain 2>/dev/null| grep "^M" | wc -l)
|
||||
n_unt=$(git status --porcelain 2>/dev/null| grep "??" | wc -l)
|
||||
|
||||
out=""
|
||||
[ "$n_sta" != 0 ] && out+="\[$txtgrn\]*$n_sta\[$txtrst\]"
|
||||
[ "$n_mod" != 0 ] && out+="\[$txtred\]+$n_mod\[$txtrst\]"
|
||||
[ "$n_unt" != 0 ] && out+="\[$txtyel\]-$n_sta\[$txtrst\]"
|
||||
echo "$out"
|
||||
}
|
||||
|
||||
set_prompt()
|
||||
{
|
||||
local is_git="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
|
||||
|
||||
local txtreset='$(tput sgr0)'
|
||||
local txtrst='$(tput sgr0)'
|
||||
local txtbold='$(tput bold)'
|
||||
local txtblack='$(tput setaf 0)'
|
||||
local txtblk='$(tput setaf 0)'
|
||||
local txtred='$(tput setaf 1)'
|
||||
local txtgreen='$(tput setaf 2)'
|
||||
local txtyellow='$(tput setaf 3)'
|
||||
local txtblue='$(tput setaf 4)'
|
||||
local txtpurple='$(tput setaf 5)'
|
||||
local txtcyan='$(tput setaf 6)'
|
||||
local txtwhite='$(tput setaf 7)'
|
||||
local txtgrn='$(tput setaf 2)'
|
||||
local txtyel='$(tput setaf 3)'
|
||||
local txtblu='$(tput setaf 4)'
|
||||
local txtpur='$(tput setaf 5)'
|
||||
local txtcyn='$(tput setaf 6)'
|
||||
local txtwht='$(tput setaf 7)'
|
||||
|
||||
# User color: red for root, yellow for others
|
||||
# User color: red for root, yel for others
|
||||
if [[ $EUID == 0 ]]; then
|
||||
PS1+="\[$txtred\]"
|
||||
else
|
||||
PS1+="\[$txtyellow\]"
|
||||
PS1+="\[$txtyel\]"
|
||||
fi
|
||||
# user@host
|
||||
PS1="\u\[$txtwhite\]@\h"
|
||||
PS1="\u\[$txtwht\]@\h"
|
||||
# Current path
|
||||
PS1+="\[$txtgreen\]\w "
|
||||
PS1+="\[$txtgrn\]\w "
|
||||
# Git repo + path in repo
|
||||
if [ "$is_git" ]; then
|
||||
local git_repo=$(basename `git rev-parse --show-toplevel` 2>/dev/null)
|
||||
local git_rel_path=$(git rev-parse --show-prefix 2>/dev/null)
|
||||
PS1+="\[$txtcyan\]$git_repo \[$txtpurple\]$git_rel_path\[$txtreset\]"
|
||||
PS1+="\[$txtcyn\]$git_repo \[$txtpur\]$git_rel_path\[$txtrst\]"
|
||||
# Green git branch
|
||||
PS1+="\[$txtgreen\]$(__git_ps1 ' (%s)')\[$txtwhite\] "
|
||||
PS1+="\[$txtgrn\]$(__git_ps1 '(%s')\[$txtwht\]"
|
||||
PS1+="$(format_modified)\[$txtgrn\])\[$txtrst\] "
|
||||
fi
|
||||
# Good old prompt, $ for user, # for root
|
||||
PS1+="\[$txtreset\]\\$ "
|
||||
PS1+="\[$txtrst\]\\$ "
|
||||
}
|
||||
export PROMPT_COMMAND='set_prompt'
|
||||
|
||||
Reference in New Issue
Block a user