all repos — dotfiles @ 210682665696efc0bb2b5227da28a7369f776774

my *nix dotfiles

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
set -o emacs
cr=$(print -n '\r')
esc=$(print -n '\033')
ps1flag=$(print -n '\001')

red="$esc[31m"
cyn="$esc[36m"
rst="$esc[0m"

git_status() {
    [[ -n "$(git rev-parse --is-inside-work-tree)" ]] ||
        return

    branch="$(git branch --show-current)"
    [[ "$branch" == "" ]] && branch="$(git rev-parse --short HEAD)"
    
    [[ "$(git status --porcelain)" != "" ]] ||
        clean=" *"

    printf ' (%s%s)' "$branch" "$clean"
}

# first, set the rootornot part
if [[ $(id -u) = 0 ]]; then
	PS1="$ps1flag$red$ps1flag#$ps1flag$rst$ps1flag"
else
	PS1=
fi

# then, combine it all
PS1="$ps1flag$cr
$ps1flag$cyn$ps1flag\$PWD$rst$(git_status)$ps1flag$rst$ps1flag
▲$PS1 "
PS2="> "