all repos — dotfiles @ f9c9735ee6e2e199e5c35a6e70027bd438164aa8

my *nix dotfiles

ksh/.kshrc.d/99-prompt.ksh (view raw)

 1set -o emacs
 2cr=$(print -n '\r')
 3esc=$(print -n '\033')
 4ps1flag=$(print -n '\001')
 5
 6red="$esc[31m"
 7cyn="$esc[36m"
 8rst="$esc[0m"
 9
10git_status() {
11    [[ -n "$(git rev-parse --is-inside-work-tree)" ]] ||
12        return
13
14    branch="$(git branch --show-current)"
15    [[ "$branch" == "" ]] && branch="$(git rev-parse --short HEAD)"
16    
17    [[ "$(git status --porcelain)" != "" ]] ||
18        clean=" *"
19
20    printf ' (%s%s)' "$branch" "$clean"
21}
22
23# first, set the rootornot part
24if [[ $(id -u) = 0 ]]; then
25	PS1="$ps1flag$red$ps1flag#$ps1flag$rst$ps1flag"
26else
27	PS1=
28fi
29
30# then, combine it all
31PS1="$ps1flag$cr
32$ps1flag$cyn$ps1flag\$PWD$rst$(git_status)$ps1flag$rst$ps1flag
33$PS1 "
34PS2="> "