commit initial
|
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...
|
6 |
#GIT_PROMPT_SYMBOL="$fg[blue]±" |
prompt adapté à git
|
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
|
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 |
|
54 |
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" |
|
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)" |
|
ajout du host dans le prompt
|
61 |
[ -n "$git_where" ] && echo "$(parse_git_state)$GIT_PROMPT_PREFIX$fg[yellow]${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX" |
commit initial
|
62 |
} |
63 | ||
64 |
precmd () { |
|
65 |
local test_code_de_sortie=$?; |
|
66 |
if [ $__LINENO__ -gt 0 ]; then |
|
ajout du host dans le prompt
|
67 |
local __PROMPT__='[ ' |
commit initial
|
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 |
|
ajout du host dans le prompt...
|
78 |
__PROMPT__+="$(git_prompt_string) " |
79 |
if [[ "$TERM" != "screen" ]]; then |
|
80 |
__PROMPT__+="\e[1;33m$HOST\e[0m:" |
|
81 |
fi |
|
commit initial
|
82 |
__PROMPT__+="\e[0;32m$([[ $UID == 0 ]] && echo '\e[47m\e[4;31m /!\ root /!\ \e[0m\e[0;31m ')" |
83 |
__PROMPT__+="$(pwd)\e[0m" |
|
84 |
echo -e "$__PROMPT__" |
|
85 |
} |
|
86 | ||
87 |
set extented_glob |
|
88 |
preexec () { |
|
89 |
if [[ "$TERM" == "screen" ]]; then |
|
90 |
TITLE='' |
|
91 |
local max=18 |
|
92 |
local mask=' ...' |
|
93 |
local separator='▰' |
|
94 |
[[ $UID == 0 ]] && 1="☢$1" |
|
95 |
if [[ ${#1} -gt $max ]]; then |
|
96 |
TITLE="${1%% *}${mask}${1:${#1%% *}+${#mask}+${#1}-${max}:${#1}} $separator ${1:${#1%% *}:${#1}}" |
|
97 |
else |
|
98 |
TITLE+="$1 $separator" |
|
99 |
fi |
|
100 |
echo -ne "\ek${TITLE}\e\\" |
|
101 |
fi |
|
102 |
} |
|
103 | ||
104 |
PS1="${GRASS_VERSION:+%BGRASS%b }zsh %(!.#.$) " |
|
105 | ||
106 |
PS2="%_ > " |
|
107 |
PS4="%_:%N(%I) >" |
|
108 | ||
109 |
# vim: filetype=zsh |