ccac342e71a3550b78bc38894a2d30daca1dea23
[dotfiles2.git] / zshrc
1 # /etc/zshrc ou ~/.zshrc
2
3 # Ecrit par Alexis de Lattre (http://www.via.ecp.fr/~alexis/formation-linux/)
4 # Modifié par Olivier Tétard
5
6 #
7 # 1. Les alias
8 #
9
10 #  Gestion du ls : couleur + touche pas aux accents
11 alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars --human-readable'
12
13 alias cp='cp --interactive'
14 alias mv='mv --interactive'
15 alias rm='rm --interactive'
16
17 alias lls='ls -l'
18 alias la='ls -a'
19 alias lla='ls -la'
20
21 # Quelques alias pratiques
22 alias less='less --quiet'
23 alias s='cd ..'
24 alias df='df --human-readable'
25 alias du='du --human-readable'
26 alias grep='grep --color=auto'
27 alias aterm='aterm -sb -sl 2000 -bg black -fg white'
28 # ssh + UTF-8
29 # alias ssh='LC_ALL=fr_FR luit ssh'
30 # alias sftp='LC_ALL=fr_FR luit sftp'
31
32 #
33 # 2. Prompt et Définition des touches
34 #
35
36 # Correspondance touches-fonction
37 bindkey '^A'    beginning-of-line       # Home
38 bindkey '^E'    end-of-line             # End
39 bindkey '^D'    delete-char             # Del
40 bindkey '\e[3~' delete-char             # Del
41 bindkey '\e[2~' overwrite-mode          # Insert
42 bindkey '\e[5~' history-search-backward # PgUp
43 bindkey '\e[6~' history-search-forward  # PgDn
44
45 # screen ou rxvt
46 if [ "$TERM" = "linux" -o "$TERM" = "screen" -o "$TERM" = "rxvt" ]
47 then
48   bindkey '\e[1~' beginning-of-line       # Home
49   bindkey '\e[4~' end-of-line             # End
50 fi
51
52 # xterm
53 if [ "$TERM" = "xterm" ]
54 then
55   bindkey '\e[H'  beginning-of-line       # Home
56   bindkey '\e[F'  end-of-line             # End
57 fi
58
59 # Gestion de la couleur pour 'ls' (exportation de LS_COLORS)
60 if [ -x /usr/bin/dircolors ]
61 then
62   if [ -r ~/.dir_colors ]
63   then
64     eval "`dircolors ~/.dir_colors`"
65   elif [ -r /etc/dir_colors ]
66   then
67     eval "`dircolors /etc/dir_colors`"
68   fi
69 fi
70
71 #
72 # 3. Options de zsh (cf 'man zshoptions')
73 #
74
75 # Je ne veux JAMAIS de beeps
76 unsetopt beep
77 unsetopt hist_beep
78 unsetopt list_beep
79
80 # On veut utiliser les options de compétions avancées
81 setopt extendedglob
82
83 # >| doit être utilisés pour pouvoir écraser un fichier déjà existant ;
84 unsetopt clobber
85
86 # Ctrl+D est équivalent à 'logout'
87 unsetopt ignore_eof
88
89 # Affiche le code de sortie si différent de '0'
90 setopt print_exit_value
91
92 # Demande confirmation pour 'rm *'
93 unsetopt rm_star_silent
94
95 # Correction orthographique des commandes
96 setopt correct
97
98 # Schémas de complétion
99
100 # - Schéma A :
101 # 1ère tabulation : complète jusqu'au bout de la partie commune
102 # 2ème tabulation : propose une liste de choix
103 # 3ème tabulation : complète avec le 1er item de la liste
104 # 4ème tabulation : complète avec le 2ème item de la liste, etc...
105 # -> c'est le schéma de complétion par défaut de zsh.
106
107 # Schéma B :
108 # 1ère tabulation : propose une liste de choix et complète avec le 1er item
109 #                   de la liste
110 # 2ème tabulation : complète avec le 2ème item de la liste, etc...
111 # Si vous voulez ce schéma, décommentez la ligne suivante :
112 #setopt menu_complete
113
114 # Schéma C :
115 # 1ère tabulation : complète jusqu'au bout de la partie commune et
116 #                   propose une liste de choix
117 # 2ème tabulation : complète avec le 1er item de la liste
118 # 3ème tabulation : complète avec le 2ème item de la liste, etc...
119 # Je n'ai malheureusement jamais réussi à mettre en place ce schéma
120 # alors qu'il me paraît être le schéma idéal !
121 # Si vous savez comment faire ça avec zsh -> alexis@via.ecp.fr
122
123 # Options de complétion
124
125 # Quand le dernier caractère d'une complétion est '/' et que l'on
126 # tape 'espace' après, le '/' est effaçé
127 setopt auto_remove_slash
128
129 # Fait la complétion sur les fichiers et répertoires cachés
130 setopt glob_dots
131
132 # Traite les liens symboliques comme il faut
133 setopt chase_links
134
135 # Quand l'utilisateur commence sa commande par '!' pour faire de la
136 # complétion historique, il n'exécute pas la commande immédiatement
137 # mais il écrit la commande dans le prompt
138 setopt hist_verify
139
140 # Si la commande est invalide mais correspond au nom d'un sous-répertoire
141 # exécuter 'cd sous-répertoire'
142 setopt auto_cd
143
144 # L'exécution de "cd" met le répertoire d'où l'on vient sur la pile
145 setopt auto_pushd
146
147 # Ignore les doublons dans la pile
148 setopt pushd_ignore_dups
149
150 # N'affiche pas la pile après un "pushd" ou "popd"
151 setopt pushd_silent
152
153 # "pushd" sans argument = "pushd $HOME"
154 setopt pushd_to_home
155
156 # Les jobs qui tournent en tâche de fond sont nicé à '0'
157 unsetopt bg_nice
158
159 # N'envoie pas de "HUP" aux jobs qui tourent quand le shell se ferme
160 unsetopt hup
161
162 #
163 # 4. Paramètres de l'historique des commandes
164 #
165
166 # Nombre d'entrées dans l'historique
167 export HISTORY=1000
168 export SAVEHIST=1000
169 # Fichier où est stocké l'historique
170 export HISTFILE=$HOME/.history
171
172 #
173 # 5. Complétion des options des commandes
174 #
175
176 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
177 zstyle ':completion:*' max-errors 3 numeric
178 zstyle ':completion:*' use-compctl false
179
180 autoload -U compinit
181 compinit
182
183 #
184 # Le prompt !
185 #
186 function precmd {
187     local TERMWIDTH
188     (( TERMWIDTH = ${COLUMNS} - 1 ))
189
190     ###
191     # Truncate the path if it's too long.
192     
193     PR_FILLBAR=""
194     PR_PWDLEN=""
195     
196     local promptsize=${#${(%):---(%n@%m:%l)---()--}}
197     local pwdsize=${#${(%):-%~}}
198     
199 #     if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
200 #           ((PR_PWDLEN=$TERMWIDTH - $promptsize))
201 #     else
202 #       PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
203 #     fi
204 # }
205 }
206
207 preexec () {
208     if [[ "$TERM" == "screen" ]]; then
209         local CMD=${1[(wr)^(*=*|sudo|-*)]}
210         echo -n "\ek$CMD\e\\"
211     fi
212 }
213
214
215 setprompt () {
216     ###
217     # Need this so the prompt will work.
218
219     setopt prompt_subst
220
221
222     ###
223     # See if we can use colors.
224
225     autoload colors zsh/terminfo
226     if [[ "$terminfo[colors]" -ge 8 ]]; then
227         colors
228     fi
229     for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
230         eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
231         eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
232         (( count = $count + 1 ))
233     done
234     PR_NO_COLOUR="%{$terminfo[sgr0]%}"
235
236
237     ###
238     # See if we can use extended characters to look nicer.
239     
240     typeset -A altchar
241     set -A altchar ${(s..)terminfo[acsc]}
242     PR_SET_CHARSET="%{$terminfo[enacs]%}"
243     PR_SHIFT_IN="%{$terminfo[smacs]%}"
244     PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
245     PR_HBAR="--"
246
247     
248     ###
249     # Decide if we need to set titlebar text.
250     
251     case $TERM in
252         xterm*)
253             PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
254             ;;
255         screen)
256             PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
257             ;;
258         *)
259             PR_TITLEBAR=''
260             ;;
261     esac
262     
263     
264     ###
265     # Decide whether to set a screen title
266     if [[ "$TERM" == "screen" ]]; then
267         PR_STITLE=$'%{\ekzsh\e\\%}'
268     else
269         PR_STITLE=''
270     fi
271     
272     ###
273     # Finally, the prompt.
274
275     PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
276 $PR_BLUE$PR_HBAR$PR_SHIFT_OUT \
277 $PR_BLUE%(!.%SROOT%s.%n)$PR_BLUE@%m:%l:$PR_MAGENTA%$PR_PWDLEN<...<%~%<<$PR_BLUE $PR_SHIFT_IN$PR_HBAR
278 $PR_BLUE$PR_HBAR$PR_SHIFT_OUT \
279 %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
280 $PR_YELLOW%D{%H:%M}\
281 $PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE$PR_NO_COLOUR '
282
283 #     RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
284 # ($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR'
285
286     PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
287 $PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
288 $PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
289 $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
290 }
291
292 setprompt                       
293 alias krypton='ssh toutoune25@miskin.fr'
294
295