all repos — dotfiles @ e707958f8ef89f3da036fa700af2ef9d65936f9e

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    [[ -d "$PWD/.git" ]] && {
13        local git_status="$(git status 2> /dev/null)"
14        local on_branch="On branch ([^${IFS}]*)"
15        local on_commit="HEAD detached at ([^${IFS}]*)"
16        status="$(git status --porcelain 2> /dev/null)"
17        local exit="$?"
18        color=""
19
20        if [[ "$exit" -eq 0 ]]; then
21            if [[ "${#status}" -eq 0 ]]; then
22                color="${grn}"  
23            else
24                color="${red}"
25            fi
26        else
27            printf ''
28        fi
29
30
31        if [[ $git_status =~ $on_branch ]]; then
32            local branch=${BASH_REMATCH[1]}
33            printf '%b'  "$color $branch $rst"
34        elif [[ $git_status =~ $on_commit ]]; then
35            local commit=${BASH_REMATCH[1]}
36            printf '%b' "$color $commit $rst"
37        fi
38    
39    }
40}
41
42prompt_pwd() {
43    printf '%b' "\001${cyn}\002$(dirs +0)\001${rst}\002"
44}
45
46rootornot() {
47    [[ "$(id -u)" -eq 0 ]] &&
48        printf '%b' "\001${red}\002#\001${rst}\002"
49}
50
51PS1='\n$(prompt_pwd)$(git_branch)\n▲$(rootornot) '
52PS2="> "