Browse Source

Amélioration prompt

master
Manfraid 3 years ago
parent
commit
4d991f2f46
5 changed files with 85 additions and 32 deletions
  1. 1
    1
      plugins/vcs.plugin.zsh
  2. 3
    0
      rc/00-helpers.zsh
  3. 28
    2
      rc/alias.zsh
  4. 43
    21
      rc/prompt.zsh
  5. 10
    8
      zshrc

+ 1
- 1
plugins/vcs.plugin.zsh View File

@@ -34,6 +34,6 @@
34 34
     }
35 35
     add-zsh-hook precmd _vbe_vcs_precmd
36 36
     _vbe_add_prompt_vcs () {
37
-	_vbe_prompt_segment cyan default ${(e)vcs_info_msg_0_}
37
+	_vbe_prompt_segment 051 234 ${(e)vcs_info_msg_0_}
38 38
     }
39 39
 }

+ 3
- 0
rc/00-helpers.zsh View File

@@ -26,3 +26,6 @@ _vbe_can_do_unicode () {
26 26
     fi
27 27
     return 0
28 28
 }
29
+
30
+
31
+

+ 28
- 2
rc/alias.zsh View File

@@ -6,6 +6,9 @@ alias du='du -h'
6 6
 alias rm='rm -i'
7 7
 alias ll='ls -l'
8 8
 alias s='cd ..'
9
+
10
+alias tmux='tmux -2'
11
+
9 12
 __() {
10 13
   local dmesg_version=${${${:-"$(dmesg --version 2> /dev/null)"}##* }:-0.0}
11 14
   if is-at-least 2.23 $dmesg_version; then
@@ -31,7 +34,8 @@ alias la='ls -a'
31 34
 alias lla='ls -la'
32 35
 # ls pour voir que les fichiers par .
33 36
 alias lsa='ls -ld .*'
34
-
37
+alias lsd='ls -ld *(-/DN)'
38
+alias lsdr='ls -ld **/*(-/DN)'
35 39
 alias sl=ls # pour les ceussent qui pensent à la fin avant le début ;-)
36 40
 
37 41
 alias grep='grep --color=always'
@@ -72,7 +76,14 @@ __() {
72 76
 
73 77
 # smv like scp
74 78
 alias smv='rsync -P --remove-source-files'
79
+alias ccp='rsync -P'
80
+alias zcp='noglob zmv -C'
81
+alias zln='noglob zmv -L'
82
+alias zmv='noglob zmv'
83
+
84
+
75 85
 (( $+functions[compdef] )) && compdef _ssh smv=scp
86
+(( $+functions[compdef] )) && compdef _ssh ccp=scp
76 87
 
77 88
 # Less generic aliases
78 89
 susu() {
@@ -85,6 +96,20 @@ susu() {
85 96
 }
86 97
 alias please='sudo $(fc -ln -1)'
87 98
 
99
+#  Pas de correction
100
+alias man='nocorrect man'
101
+alias mysql='nocorrect mysql'
102
+alias mysqlshow='nocorrect mysqlshow'
103
+alias mkdir='nocorrect mkdir'
104
+alias mv='nocorrect mv --interactive'
105
+alias cp='nocorrect cp --interactive'
106
+alias rm='nocorrect rm --interactive'
107
+alias rj='nocorrect rj'
108
+alias cd='nocorrect cd'
109
+alias ln='nocorrect ln -i'
110
+
111
+
112
+
88 113
 # Aliases as a function
89 114
 evince() { command evince ${*:-*.(djvu|dvi|pdf)(om[1])} }
90 115
 md() { command mkdir -p $1 && cd $1 }
@@ -356,7 +381,8 @@ colortest() {
356 381
         for green in {0..5}; do
357 382
             for blue in {0..5}; do
358 383
                 bg=$((16 + red * 36 + green * 6 + blue))
359
-                printf "\e[48;5;%dm  " bg
384
+                fg=$((16 + (5-red) * 36 + (5-green) * 6 + 5 - blue))
385
+                printf "\e[48;5;%dm\e[38;5;%dm%3d " bg fg bg
360 386
             done
361 387
             printf "\e[0m "
362 388
         done

+ 43
- 21
rc/prompt.zsh View File

@@ -19,6 +19,27 @@ else
19 19
     }
20 20
 fi
21 21
 
22
+typeset -AHg FX FG BG
23
+
24
+FX=(
25
+ reset          "\e[00m"
26
+ bold           "\e[01m"
27
+ no-bold        "\e[22m"
28
+ italic         "\e[02m"
29
+ no-italic      "\e[23m"
30
+ underline      "\e[04m"
31
+ no-underline   "\e[24m"
32
+ blink          "\e[05m"
33
+ no-blink       "\e[25m"
34
+ reverse        "\e[07m"
35
+ no-reverse     "\e[27m"
36
+)
37
+
38
+for color in {000..255}; do
39
+ FG[$color]="\e[38;5;${color}m"
40
+ BG[$color]="\e[48;5;${color}m"
41
+done
42
+
22 43
 # Stolen from https://github.com/sindresorhus/pure/blob/master/pure.zsh
23 44
 _vbe_human_time () {
24 45
     local tmp=$1
@@ -34,14 +55,14 @@ _vbe_human_time () {
34 55
     print -n "${result[1,2]}"
35 56
 }
36 57
 
37
-CURRENT_BG=NONE
58
+CURRENT_BG=0
38 59
 _vbe_prompt_segment() {
39 60
   local b f
40
-  [[ -n $1 ]] && b="$bg[$1]" || b="$bg[default]"
41
-  [[ -n $2 ]] && f="$fg[$2]" || f="$fg[default]"
61
+  [[ -n $1 ]] && b=$BG[$1] || b=$BG[000]
62
+  [[ -n $2 ]] && f=$FG[$2] || f=$FG[011]
42 63
   [[ -n $3 ]] || return
43
-  if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
44
-      print -n " %{%b$b$fg[$CURRENT_BG]%}${PRCH[end]}%{$f%} "
64
+  if [[ $CURRENT_BG != 0 && $1 != $CURRENT_BG ]]; then
65
+      print -n " %{%b$b$FG[$CURRENT_BG]%}${PRCH[end]}%{$f%} "
45 66
   elif [[ $1 == $CURRENT_BG ]]; then
46 67
       print -n " %{%b$b$f%}${PRCH[sep]} "
47 68
   else
@@ -52,21 +73,22 @@ _vbe_prompt_segment() {
52 73
 }
53 74
 _vbe_prompt_end() {
54 75
   if [[ -n $CURRENT_BG ]]; then
55
-    print -n " %{%b$fg[$CURRENT_BG]%}${PRCH[end]}"
76
+    print -n " %{%b$FG[$CURRENT_BG]%}${PRCH[end]}"
56 77
   else
57 78
     print -n "%{%b%}"
58 79
   fi
59
-  print -n "%{${reset_color}%}"
60
-  CURRENT_BG=''
80
+  print -n "%{$FX[reset]%}"
81
+  CURRENT_BG=0
61 82
 }
62 83
 
63 84
 _vbe_prompt () {
64 85
     local retval=$?
65
-    local fond="ligh_blue"
86
+    local fond=196
66 87
     # user@host
67
-    local f=${(%):-%(!.red.${${SSH_TTY:+magenta}:-green})}
68
-    _vbe_prompt_segment black $f \
69
-        %B%n%b%{${fg[cyan]}%}${${(%):-%n}:+@}%B%{${bg[black]}${fg[$f]}%}%M
88
+    local f=${(%):-%(!.196.${${SSH_TTY:+028}:-046})}
89
+    
90
+    _vbe_prompt_segment 234 $f \
91
+        $FX[bold]%n$FX[no-bold]%{${FG[051]}%}${${(%):-%n}:+@}%{${BG[234]}${FG[$f]}%}$FX[bold]%M$FX[no-bold]
70 92
 
71 93
     # Directory
72 94
     local -a segs
@@ -74,20 +96,20 @@ _vbe_prompt () {
74 96
     segs=(${(s./.)${(%):-%${len}<${PRCH[ellipsis]}<%~}})
75 97
     [[ ${#segs} == 0 ]] && segs=(/)
76 98
     if [[ -w $PWD ]]; then
77
-      fond="cyan"
99
+      fond=034
78 100
     else
79
-      fond="red"
101
+      fond=196
80 102
     fi
81 103
 
82
-    for seg in ${segs[1,-2]}; do
83
-        _vbe_prompt_segment $fond black $seg
104
+    for seg in ${segs[1,-1]}; do
105
+        _vbe_prompt_segment $fond 234 $seg
84 106
     done
85
-    _vbe_prompt_segment $fond black ${segs[-1]}
107
+    #_vbe_prompt_segment $fond 88 ${segs[-1]}
86 108
     _vbe_prompt_end
87 109
 
88 110
     # New line
89 111
     print
90
-    CURRENT_BG=NONE
112
+    CURRENT_BG=0
91 113
 
92 114
     # Additional info
93 115
     _vbe_add_prompt
@@ -96,12 +118,12 @@ _vbe_prompt () {
96 118
     local now=$EPOCHSECONDS
97 119
     local elapsed=$(($now - ${_vbe_cmd_timestamp:-$now}))
98 120
     (($elapsed >= 5)) && \
99
-        _vbe_prompt_segment white black "$(_vbe_human_time $elapsed)"
121
+        _vbe_prompt_segment 255 008 "$(_vbe_human_time $elapsed)"
100 122
 
101 123
     # Error code
102 124
     (( $retval )) && \
103
-        _vbe_prompt_segment red default %B${PRCH[retb]}'%?'${PRCH[reta]} || \
104
-        _vbe_prompt_segment green white %B${PRCH[ok]}
125
+        _vbe_prompt_segment 196 010 %B${PRCH[retb]}'%?'${PRCH[reta]} || \
126
+        _vbe_prompt_segment 034 234 %B${PRCH[ok]}
105 127
 
106 128
     _vbe_prompt_end
107 129
 }

+ 10
- 8
zshrc View File

@@ -5,14 +5,14 @@
5 5
 [ -t 1 ] || exec /bin/sh
6 6
 
7 7
 # Execute tmux if available and if we have some configuration for it
8
-(( $+commands[tmux] )) && \
9
-    [[ -f ~/.tmux.conf && \
10
-             $PPID != 1 && \
11
-             $$ != 1 && \
12
-             $TERM != linux && \
13
-             $TERM != screen* && \
14
-             -z $TMUX ]] && \
15
-    exec tmux
8
+#(( $+commands[tmux] )) && \
9
+#    [[ -f ~/.tmux.conf && \
10
+#             $PPID != 1 && \
11
+#             $$ != 1 && \
12
+#             $TERM != linux && \
13
+#             $TERM != screen* && \
14
+#             -z $TMUX ]] && \
15
+#    exec tmux
16 16
 
17 17
 ZSH=${ZSH:-${ZDOTDIR:-$HOME}/.zsh}
18 18
 fpath=($ZSH/functions $ZSH/completions $fpath)
@@ -27,6 +27,8 @@ autoload -U is-at-least
27 27
 { autoload -U +X add-zsh-hook || unset -f add-zsh-hook } 2> /dev/null
28 28
 
29 29
 __() {
30
+    local -a plugins
31
+    plugins=(vcs)
30 32
     for config_file ($ZSH/rc/*.zsh) source $config_file
31 33
     for plugin ($plugins) source $ZSH/plugins/$plugin.plugin.zsh
32 34
     [ ! -e $ZSH/env ] || . $ZSH/env

Loading…
Cancel
Save