all repos — dotfiles @ 5cae5ce7fa8585282f99f5b0c57b3e31ba471a58

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 " ${grn} $branch ${rst}"
21    elif [[ $git_status =~ $on_commit ]]; then
22        local commit=${BASH_REMATCH[1]}
23        echo -ne " ${ylw} $commit ${rst}"
24    fi
25}
26
27prompt_pwd() {
28   path="$(echo $PWD)"
29   echo -ne "\001${gry}\002$path\001${rst}\002"
30}
31
32rootornot() {
33    if [[ "$(id -u)" -eq 0 ]]; then
34        echo -ne "\001${red}\002#\001${rst}\002"
35    else
36        echo -ne "›"
37    fi
38}
39
40PS1='\n$(prompt_pwd)$(git_branch)\n$(rootornot) '
41PS2="> "