Add .zshrc
[dotfiles2.git] / zshrc
diff --git a/zshrc b/zshrc
new file mode 100644 (file)
index 0000000..ccac342
--- /dev/null
+++ b/zshrc
@@ -0,0 +1,295 @@
+# /etc/zshrc ou ~/.zshrc
+
+# Ecrit par Alexis de Lattre (http://www.via.ecp.fr/~alexis/formation-linux/)
+# Modifié par Olivier Tétard
+
+#
+# 1. Les alias
+#
+
+#  Gestion du ls : couleur + touche pas aux accents
+alias ls='ls --classify --tabsize=0 --literal --color=auto --show-control-chars --human-readable'
+
+alias cp='cp --interactive'
+alias mv='mv --interactive'
+alias rm='rm --interactive'
+
+alias lls='ls -l'
+alias la='ls -a'
+alias lla='ls -la'
+
+# Quelques alias pratiques
+alias less='less --quiet'
+alias s='cd ..'
+alias df='df --human-readable'
+alias du='du --human-readable'
+alias grep='grep --color=auto'
+alias aterm='aterm -sb -sl 2000 -bg black -fg white'
+# ssh + UTF-8
+# alias ssh='LC_ALL=fr_FR luit ssh'
+# alias sftp='LC_ALL=fr_FR luit sftp'
+
+#
+# 2. Prompt et Définition des touches
+#
+
+# Correspondance touches-fonction
+bindkey '^A'    beginning-of-line       # Home
+bindkey '^E'    end-of-line             # End
+bindkey '^D'    delete-char             # Del
+bindkey '\e[3~' delete-char             # Del
+bindkey '\e[2~' overwrite-mode          # Insert
+bindkey '\e[5~' history-search-backward # PgUp
+bindkey '\e[6~' history-search-forward  # PgDn
+
+# screen ou rxvt
+if [ "$TERM" = "linux" -o "$TERM" = "screen" -o "$TERM" = "rxvt" ]
+then
+  bindkey '\e[1~' beginning-of-line       # Home
+  bindkey '\e[4~' end-of-line             # End
+fi
+
+# xterm
+if [ "$TERM" = "xterm" ]
+then
+  bindkey '\e[H'  beginning-of-line       # Home
+  bindkey '\e[F'  end-of-line             # End
+fi
+
+# Gestion de la couleur pour 'ls' (exportation de LS_COLORS)
+if [ -x /usr/bin/dircolors ]
+then
+  if [ -r ~/.dir_colors ]
+  then
+    eval "`dircolors ~/.dir_colors`"
+  elif [ -r /etc/dir_colors ]
+  then
+    eval "`dircolors /etc/dir_colors`"
+  fi
+fi
+
+#
+# 3. Options de zsh (cf 'man zshoptions')
+#
+
+# Je ne veux JAMAIS de beeps
+unsetopt beep
+unsetopt hist_beep
+unsetopt list_beep
+
+# On veut utiliser les options de compétions avancées
+setopt extendedglob
+
+# >| doit être utilisés pour pouvoir écraser un fichier déjà existant ;
+unsetopt clobber
+
+# Ctrl+D est équivalent à 'logout'
+unsetopt ignore_eof
+
+# Affiche le code de sortie si différent de '0'
+setopt print_exit_value
+
+# Demande confirmation pour 'rm *'
+unsetopt rm_star_silent
+
+# Correction orthographique des commandes
+setopt correct
+
+# Schémas de complétion
+
+# - Schéma A :
+# 1ère tabulation : complète jusqu'au bout de la partie commune
+# 2ème tabulation : propose une liste de choix
+# 3ème tabulation : complète avec le 1er item de la liste
+# 4ème tabulation : complète avec le 2ème item de la liste, etc...
+# -> c'est le schéma de complétion par défaut de zsh.
+
+# Schéma B :
+# 1ère tabulation : propose une liste de choix et complète avec le 1er item
+#                   de la liste
+# 2ème tabulation : complète avec le 2ème item de la liste, etc...
+# Si vous voulez ce schéma, décommentez la ligne suivante :
+#setopt menu_complete
+
+# Schéma C :
+# 1ère tabulation : complète jusqu'au bout de la partie commune et
+#                   propose une liste de choix
+# 2ème tabulation : complète avec le 1er item de la liste
+# 3ème tabulation : complète avec le 2ème item de la liste, etc...
+# Je n'ai malheureusement jamais réussi à mettre en place ce schéma
+# alors qu'il me paraît être le schéma idéal !
+# Si vous savez comment faire ça avec zsh -> alexis@via.ecp.fr
+
+# Options de complétion
+
+# Quand le dernier caractère d'une complétion est '/' et que l'on
+# tape 'espace' après, le '/' est effaçé
+setopt auto_remove_slash
+
+# Fait la complétion sur les fichiers et répertoires cachés
+setopt glob_dots
+
+# Traite les liens symboliques comme il faut
+setopt chase_links
+
+# Quand l'utilisateur commence sa commande par '!' pour faire de la
+# complétion historique, il n'exécute pas la commande immédiatement
+# mais il écrit la commande dans le prompt
+setopt hist_verify
+
+# Si la commande est invalide mais correspond au nom d'un sous-répertoire
+# exécuter 'cd sous-répertoire'
+setopt auto_cd
+
+# L'exécution de "cd" met le répertoire d'où l'on vient sur la pile
+setopt auto_pushd
+
+# Ignore les doublons dans la pile
+setopt pushd_ignore_dups
+
+# N'affiche pas la pile après un "pushd" ou "popd"
+setopt pushd_silent
+
+# "pushd" sans argument = "pushd $HOME"
+setopt pushd_to_home
+
+# Les jobs qui tournent en tâche de fond sont nicé à '0'
+unsetopt bg_nice
+
+# N'envoie pas de "HUP" aux jobs qui tourent quand le shell se ferme
+unsetopt hup
+
+#
+# 4. Paramètres de l'historique des commandes
+#
+
+# Nombre d'entrées dans l'historique
+export HISTORY=1000
+export SAVEHIST=1000
+# Fichier où est stocké l'historique
+export HISTFILE=$HOME/.history
+
+#
+# 5. Complétion des options des commandes
+#
+
+zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
+zstyle ':completion:*' max-errors 3 numeric
+zstyle ':completion:*' use-compctl false
+
+autoload -U compinit
+compinit
+
+#
+# Le prompt !
+#
+function precmd {
+    local TERMWIDTH
+    (( TERMWIDTH = ${COLUMNS} - 1 ))
+
+    ###
+    # Truncate the path if it's too long.
+    
+    PR_FILLBAR=""
+    PR_PWDLEN=""
+    
+    local promptsize=${#${(%):---(%n@%m:%l)---()--}}
+    local pwdsize=${#${(%):-%~}}
+    
+#     if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
+#          ((PR_PWDLEN=$TERMWIDTH - $promptsize))
+#     else
+#      PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
+#     fi
+# }
+}
+
+preexec () {
+    if [[ "$TERM" == "screen" ]]; then
+       local CMD=${1[(wr)^(*=*|sudo|-*)]}
+       echo -n "\ek$CMD\e\\"
+    fi
+}
+
+
+setprompt () {
+    ###
+    # Need this so the prompt will work.
+
+    setopt prompt_subst
+
+
+    ###
+    # See if we can use colors.
+
+    autoload colors zsh/terminfo
+    if [[ "$terminfo[colors]" -ge 8 ]]; then
+       colors
+    fi
+    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
+       eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
+       eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
+       (( count = $count + 1 ))
+    done
+    PR_NO_COLOUR="%{$terminfo[sgr0]%}"
+
+
+    ###
+    # See if we can use extended characters to look nicer.
+    
+    typeset -A altchar
+    set -A altchar ${(s..)terminfo[acsc]}
+    PR_SET_CHARSET="%{$terminfo[enacs]%}"
+    PR_SHIFT_IN="%{$terminfo[smacs]%}"
+    PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
+    PR_HBAR="--"
+
+    
+    ###
+    # Decide if we need to set titlebar text.
+    
+    case $TERM in
+       xterm*)
+           PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
+           ;;
+       screen)
+           PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
+           ;;
+       *)
+           PR_TITLEBAR=''
+           ;;
+    esac
+    
+    
+    ###
+    # Decide whether to set a screen title
+    if [[ "$TERM" == "screen" ]]; then
+       PR_STITLE=$'%{\ekzsh\e\\%}'
+    else
+       PR_STITLE=''
+    fi
+    
+    ###
+    # Finally, the prompt.
+
+    PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
+$PR_BLUE$PR_HBAR$PR_SHIFT_OUT \
+$PR_BLUE%(!.%SROOT%s.%n)$PR_BLUE@%m:%l:$PR_MAGENTA%$PR_PWDLEN<...<%~%<<$PR_BLUE $PR_SHIFT_IN$PR_HBAR
+$PR_BLUE$PR_HBAR$PR_SHIFT_OUT \
+%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
+$PR_YELLOW%D{%H:%M}\
+$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE$PR_NO_COLOUR '
+
+#     RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
+# ($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR'
+
+    PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
+$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
+$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
+$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
+}
+
+setprompt                       
+alias krypton='ssh toutoune25@miskin.fr'
+
+