all repos — dotfiles @ 26acc67d22e33ed9de159742ed2d75311ed42337

my *nix dotfiles

bash/prompt (view raw)

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