all repos — dotfiles @ 8ce58989ee8649b21f47e086f6cf4dec73a3f4da

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
16    if [[ $git_status =~ $on_branch ]]; then
17        local branch=${BASH_REMATCH[1]}
18        echo -ne "${ylw} $branch ${rst}"
19    elif [[ $git_status =~ $on_commit ]]; then
20        local commit=${BASH_REMATCH[1]}
21        echo -ne "${cyn} $commit ${rst}"
22    fi
23}
24
25dirtyorclean() {
26    status="$(git status --porcelain 2> /dev/null)"
27    local exit="$?"
28    if [[ "$exit" -eq 0 ]]; then
29        if [[ ${#status} -eq 0 ]]; then
30            echo -ne "${grn}${rst}"
31        else
32            echo -ne "${red}×${rst}"
33        fi
34    else
35        echo -ne ""
36    fi
37}
38
39prompt_pwd() {
40    echo -ne "\001${cyn}\002$(dirs +0)\001${rst}\002"
41}
42
43rootornot() {
44    [[ "$(id -u)" -eq 0 ]] &&
45        echo -ne "\001${red}\002#\001${rst}\002"
46}
47
48PS1='\n$(prompt_pwd)$(git_branch)$(dirtyorclean)\n▲$(rootornot) '
49PS2="> "