config / .zsh / prompt /
Newer Older
113 lines | 3.701kb
commit initial
Sébastien MARQUE authored on 2016-10-31
1
autoload -U colors
2
colors
3
#setopt prompt_subst
4

            
5
# Modify the colors and symbols in these variables as desired.
amélioration du prompt en su...
Sébastien MARQUE authored on 2016-11-07
6
#GIT_PROMPT_SYMBOL="$fg[blue]±"
prompt adapté à git
Sébastien MARQUE authored on 2016-11-04
7
GIT_PROMPT_PREFIX="$fg[green][$reset_color"
8
GIT_PROMPT_SUFFIX="$fg[green]]$reset_color"
9
GIT_PROMPT_AHEAD="$fg[red]ANUM$reset_color"
10
GIT_PROMPT_BEHIND="$fg[cyan]BNUM$reset_color"
11
GIT_PROMPT_MERGING="$fg[magenta]Z$reset_color"
12
GIT_PROMPT_UNTRACKED="$fg[red]●$reset_color"
13
GIT_PROMPT_MODIFIED="$fg[yellow]●$reset_color"
14
GIT_PROMPT_STAGED="$fg[green]●$reset_color"
commit initial
Sébastien MARQUE authored on 2016-10-31
15

            
16
# Show Git branch/tag, or name-rev if on detached head
17
parse_git_branch() {
18
    (git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
19
}
20

            
21
# Show different symbols as appropriate for various Git repository states
22
parse_git_state() {
23
# Compose this value via multiple conditional appends.
24
    local GIT_STATE=""
25

            
26
    local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
27
    if [ "$NUM_AHEAD" -gt 0 ]; then
28
        GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
29
    fi
30

            
31
    local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
32
    if [ "$NUM_BEHIND" -gt 0 ]; then
33
        GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
34
    fi
35

            
36
    local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
37
    if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
38
        GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
39
    fi
40

            
41
    if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
42
        GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
43
    fi
44

            
45
    if ! git diff --quiet 2> /dev/null; then
46
        GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
47
    fi
48

            
49
    if ! git diff --cached --quiet 2> /dev/null; then
50
        GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
51
    fi
52

            
53
    if [[ -n $GIT_STATE ]]; then
amélioration du prompt pour ...
Sébastien MARQUE authored on 2017-03-03
54
        echo "$GIT_STATE "
commit initial
Sébastien MARQUE authored on 2016-10-31
55
    fi
56
}
57

            
58
# If inside a Git repository, print its branch and state
59
git_prompt_string() {
60
    local git_where="$(parse_git_branch)"
amélioration du prompt pour ...
Sébastien MARQUE authored on 2017-03-03
61
    [ -n "$git_where" ] && echo "$GIT_PROMPT_PREFIX$(parse_git_state)$fg[yellow]${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX "
commit initial
Sébastien MARQUE authored on 2016-10-31
62
}
63

            
64
precmd () {
65
    local test_code_de_sortie=$?;
66
    if [ $__LINENO__ -gt 0 ]; then
ajout du host dans le prompt
Sébastien MARQUE authored on 2016-11-11
67
        local __PROMPT__='[ '
commit initial
Sébastien MARQUE authored on 2016-10-31
68
        [[ $test_code_de_sortie != 0 ]] && __PROMPT__+="\e[41m\e[1;39m $test_code_de_sortie \e[0m "
69
        __PROMPT__+="\e[0;33m$(date '+%H:%M %x')\e[0m ]\n\n"
70
    fi
71
    (( __LINENO__ = $__LINENO__+ 1))
72
    nbrj=$(jobs | grep -c '^\[');
73
    if [ $nbrj -gt 1 ]; then
74
        __PROMPT__+="\e[1;34m$nbrj\e[0;34m jobs en cours\n"
75
    elif [ $nbrj -gt 0 ]; then 
76
        __PROMPT__+="\e[1;34m$nbrj\e[0;34m job en cours\n"
77
    fi
prompt: affiche le repo git ...
Sébastien MARQUE authored on 2017-03-03
78
    local GIT_PROMPT_STRING="$(git_prompt_string)"
79
    if [ -n "$GIT_PROMPT_STRING" ]; then
80
        local GIT_REPO_DIR="$(git rev-parse --show-toplevel 2> /dev/null)"
81
    fi
82
    __PROMPT__+="$GIT_PROMPT_STRING"
fix: affichage du nom d'hôte...
Sébastien MARQUE authored on 2016-12-31
83
    if test $SHLVL -eq 1 -o $TERM != "screen"; then
ajout du host dans le prompt...
Sébastien MARQUE authored on 2016-11-11
84
        __PROMPT__+="\e[1;33m$HOST\e[0m:"
85
    fi
commit initial
Sébastien MARQUE authored on 2016-10-31
86
    __PROMPT__+="\e[0;32m$([[ $UID == 0 ]] && echo '\e[47m\e[4;31m /!\ root /!\ \e[0m\e[0;31m ')"
prompt: moins de couleur = m...
Sébastien MARQUE authored on 2017-03-03
87
    __PROMPT__+="${PWD/$GIT_REPO_DIR/\e[4m$GIT_REPO_DIR\e[0;32m}\e[0m"
commit initial
Sébastien MARQUE authored on 2016-10-31
88
    echo -e "$__PROMPT__"
89
}
90

            
91
set extented_glob
92
preexec () {
93
    if [[ "$TERM" == "screen" ]]; then
94
        TITLE=''
95
        local max=18
96
        local mask=' ...'
97
        local separator='▰'
98
        [[ $UID == 0 ]] && 1="☢$1"
99
        if [[ ${#1} -gt $max ]]; then
100
            TITLE="${1%% *}${mask}${1:${#1%% *}+${#mask}+${#1}-${max}:${#1}} $separator ${1:${#1%% *}:${#1}}"
101
        else
102
            TITLE+="$1 $separator"
103
        fi
104
        echo -ne "\ek${TITLE}\e\\"
105
    fi
106
}
107

            
108
PS1="${GRASS_VERSION:+%BGRASS%b }zsh %(!.#.$) "
109

            
110
PS2="%_ > "
111
PS4="%_:%N(%I) >"
112

            
113
# vim: filetype=zsh