all repos — dotfiles @ 54d62703aea39a26651cd35cb339724ff3845cee

my *nix dotfiles

bash/.bashrc.d/99-prompt.bash (view raw)

 1red="\e[31m"
 2grn="\e[32m"
 3ylw="\e[33m"
 4cyn="\e[36m"
 5blu="\e[34m"
 6prp="\e[35m"
 7bprp="\e[35;1m"
 8gry="\e[94m"
 9rst="\e[0m"
10
11git_branch() {
12    local git_status="$(git status 2> /dev/null)"
13    local on_branch="On branch ([^${IFS}]*)"
14    local on_commit="HEAD detached at ([^${IFS}]*)"
15    status="$(git status --porcelain 2> /dev/null)"
16    local exit="$?"
17    color=""
18
19    if [[ "$exit" -eq 0 ]]; then
20        if [[ "${#status}" -eq 0 ]]; then
21            color="${grn}"  
22        else
23            color="${red}"
24        fi
25    else
26        printf ''
27    fi
28
29
30    if [[ $git_status =~ $on_branch ]]; then
31        local branch=${BASH_REMATCH[1]}
32        printf '%b'  "$color $branch $rst"
33    elif [[ $git_status =~ $on_commit ]]; then
34        local commit=${BASH_REMATCH[1]}
35        printf '%b' "$color $commit $rst"
36    fi
37}
38
39prompt_pwd() {
40    printf '%b' "\001${cyn}\002$(dirs +0)\001${rst}\002"
41}
42
43rootornot() {
44    [[ "$(id -u)" -eq 0 ]] &&
45        printf '%b' "\001${red}\002#\001${rst}\002"
46}
47
48PS1='\n$(prompt_pwd)$(git_branch)\n▲$(rootornot) '
49PS2="> "