guest@dotshare [~/groups/shells/zsh] $ ls Prompt-Git-branch/ | cat

Prompt-Git branch (scrot, raw, dl) (+2 likes)

ivo Jun 25, 2011 (shells/zsh)

SCROT

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# prompt
function prompt_git_dirty() {
    gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
    
    if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
        echo -n $PR_LIGHT_YELLOW
    elif [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then
        echo -n $PR_LIGHT_RED
    else
        echo -n $PR_LIGHT_MAGENTA
    fi
}

function prompt_current_branch() {
    ref=$(git symbolic-ref HEAD 2> /dev/null) || return 1
    echo ${ref#refs/heads/}
}

function prompt_hostname()
{
    case "`hostname`" in
        "Arch")
            echo -n "${PR_LIGHT_YELLOW}Arch${PR_NO_COLOR}";;    
    esac
}

function precmd() # Uses: setting user/root PROMPT1 variable and rehashing commands list
{
    # Last command status
    cmdstatus=$?
    sadface=`[ "$cmdstatus" != "0" ] && echo "${PR_RED}:(${PR_NO_COLOR} "`

    # Colours
    usercolour=`[ $UID != 0 ]   && echo $PR_BLUE      || echo $PR_RED`
    usercolour2=`[ $UID != 0 ]  && echo $WHITE || echo $PR_RED`
    dircolour=`[ -w "\`pwd\`" ] && echo $PR_YELLOW       || echo $PR_RED`

    # Git branch
    git="[branch: `prompt_git_dirty``prompt_current_branch`${blue}]"

export PROMPT="
${usercolour}┌─[${dircolour}%n${PR_NO_COLOR}«»`prompt_hostname`${usercolour}]─────────────────────────${dircolour}[%~]${PR_NO_COLOR} `prompt_current_branch &>/dev/null && echo -n $git`
${usercolour}└─${sadface}${usercolour}${dircolour}(%T)(%l)${usercolour}keep it simple ─╼ ${PR_NO_COLOR}"                          
}                                        
#
#based on Barrucadu (prompt):https://bbs.archlinux.org/viewtopic.php?pid=831695#p831695
# 

CLICK TO VIEW

x

Comments

rstrcogburn said about 5 years ago

nice ivo, i’ve wondered how to do this even though I have it working in my grml-zsh config. Muchisimas Gracias.

ivo said about 5 years ago

@rstrcogburn
Thank you.

crshd said about 5 years ago

ZSH actually has a built-in module to display VCS info, i recommend looking into that.