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