zshrc
author Mikael Berthe <mikael@lilotux.net>
Sat, 14 Jul 2012 23:13:35 +0200
changeset 6 7671e95ab8b0
parent 0 7215ca490221
child 8 3f68f355bf1a
permissions -rw-r--r--
Change my local mkcd alias into a function I was grepping for my mkcd alias in the wrong terminal and found another version, which turned out to be a good thing as Frank's implementation looks better :) https://dev.0x50.de/projects/ftzsh/repository/revisions/master/entry/functions/mkcd

#
# This file is sourced only for interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin

# Copyright (c) 1995 Antoine VOUILLON
# Copyright (c) 1995-1999 Farzad FARID
# Copyright (c) Mikael BERTHE, 2001-2012
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# La ligne suivante provoque parfois un message d'erreur non gênant
unalias run-help 2>/dev/null
autoload run-help

autoload -U zmv

# Protection des fichiers    : rw-rw-r--
# Protection des répertoires : rwxrwxr-x
if [[ $UID -eq 0 ]]; then
  umask 022
else
  umask 002
fi

ulimit -c 0
# Pas de limite pour les coredump
#ulimit -c unlimited
#unlimit coredumpsize

########################
# Definition du prompt #
########################

# Chargement des variables pour les couleurs
autoload colors; colors;

# Prompt complet (date, login, tty, hostname, cwd) sur une ligne
# (Invite de commande de secours...)
export PS1="%T %B[%n:%l]%b %S%m%s:%~%# "

# Prompt complet sur 2 lignes, N&B
#export PS1="%B%~%b
#%D{%m%d %H:%M} %B[%n:%l]%b %S%m%s%# "

export PS2='%_.. > '

# Enable my Vim-like mode for supported terms
if [[ "$TERM" == "rxvt" ||
      "$TERM" == "rxvt-256color" ||
      "$TERM" == "rxvt-unicode" ||
      "$TERM" == "rxvt-unicode-256color" ]]
then
    export SHOWMODE="on"
fi

set shell=$SHELL
#cdpath=(~)

if [[ -z "$FPATH" ]]; then
  if [[ -d "/usr/lib/zsh/functions" ]]; then
    FPATH="/usr/lib/zsh/functions"
  elif [[ -d "/usr/share/zsh/functions" ]]; then
    FPATH="/usr/share/zsh/functions"
  else
    echo "zsh: Could not set FPATH variable: no ../zsh/functions directory"
  fi
fi

# Pour configurer les couleurs créer le fichier /etc/LS_COLORS avec la
# commande "dircolors --print-database > /etc/LS_COLORS" et l'éditer.
# Taper 'man dircolors' pour plus de details
if [[ -x /usr/bin/dircolors ]]; then
  if [[ -e /etc/LS_COLORS ]]; then
    eval $(dircolors -b /etc/LS_COLORS)
  else
    eval $(dircolors -b)
  fi
  LS_OPTIONS=(--color=auto)
  export LS_OPTIONS
fi


####################
# Options du shell #
####################

# Les noms des options sont écrits avec le souligné '_' optionnel pour
# faciliter la recherche dans la documentation de zsh.

# Options de completion. Complète les noms de commandes/fichiers avec TAB
# listes toutes les possibilités, ne beep pas, boucle entre les choix par
# appui répété sur TAB.
#setopt menu_complete
setopt auto_list
setopt list_types
setopt no_list_beep
#setopt bash_auto_list

# Correction automatique
setopt correct
unsetopt correct_all

# Autres options

# chdir « intelligent »
setopt auto_cd

# On ne modifie pas des fichiers existants avec '>' et '>>'
setopt no_clobber

unsetopt bg_nice
setopt no_flow_control
setopt no_hup
unsetopt sun_keyboard_hack

# On n'écrase pas le fichier d'historique
setopt append_history
# On autorise les commentaires
setopt interactive_comments
# Les lignes commençant par une espace ne seront pas archivées
setopt hist_ignore_space
# fc -l ne sera pas archivé
setopt hist_no_store
# Pas de doublons dans  l'historique
setopt hist_ignore_dups
# Les répertoires sont automatiquement mis dans la pile (cf. pushd, popd...)
setopt auto_pushd
# ... sans doublons
setopt pushd_ignore_dups
# Affiche la valeur de retour d'un programme (si non nulle)
setopt print_exit_value
# Essaie de réduire la liste des complétions
setopt list_packed

#setopt nobeep


############################
# Historique des commandes #
############################

export SAVEHIST=4096
export HISTSIZE=4096
export HIST_EXPIRE_DUPS_FIRST
export HISTFILE=$HOME/.history


#############################
# Configuration des touches #
#############################

# Pour que la touche Alt marche dans les xterm
bindkey -e
if [[ -z ${TERM:#xterm*} || -z ${TERM:#rxvt*} || -z ${TERM:#linux*} ]]; then
  stty pass8
  # L'option -m empêche l'utilisation des accents (è = ESC-h, etc.)
  #bindkey -me
fi

# Universelle
#bindkey '^Q'    quoted-insert
bindkey '[2~' overwrite-mode                    # Ins
bindkey '[3~' delete-char                       # Suppr
bindkey '[5~' history-beginning-search-backward # PgUp
bindkey '[6~' history-beginning-search-forward  # PgDn
bindkey '^[^I'  reverse-menu-complete             # ESC-Tab
bindkey '^Xc'   copy-prev-word
bindkey '^Xf'   _correct_filename
bindkey '^Xm'   _most_recent_file


# Sur la console
if [[ "$TERM" == "console" || "$TERM" == "vt100" ]]; then
  bindkey '^[[1~' beginning-of-line       # Home
  bindkey '^[[4~' end-of-line             # End
fi

# Dans un xterm term=linux
if [[ -z ${TERM:#linux*} || -z ${TERM:#screen} ]]; then
  bindkey '^[[H'  beginning-of-line       # Home
  bindkey '^[[F'  end-of-line             # End
  bindkey '[1~'  beginning-of-line       # Home
  bindkey '[4~'  end-of-line             # End
fi

# Dans un xterm
if [[ -z ${TERM:#xterm*} ]]; then
  bindkey '^[[H'  beginning-of-line       # Home
  bindkey '^[[F'  end-of-line             # End
  bindkey '[1~'  beginning-of-line       # Home
  bindkey '[4~'  end-of-line             # End
fi

# Dans un rxvt
if [[ -z ${TERM:#rxvt*} ]]; then
  bindkey '^[[7~' beginning-of-line       # Home
  bindkey '^[[8~' end-of-line             # End
fi

# Sur un xterm, on differencie backspace et delete (?).
if [[ -z ${TERM:#xterm*} ]]
then
  bindkey '^H'  backward-delete-char    # Backspace
  bindkey '^?'  backward-delete-char    # Backspace
fi

# En combinaison avec le "keycode 22 = Backspace" du .Xmodmap pour
# faire marcher le backspace dans Netscape
stty erase '^?'

#######################################################
# Completion, lire le man pour plus de renseignements #
#######################################################

#compctl -g '*(-/)' cd pushd
compctl -g '.*(-/) *(-/)' cd pushd
compctl -g '.*(-/) *(-/)' rmdir
compctl -g '*.Z *.z *.gz *.tgz *(-/)' zcat gunzip
compctl -g '*.Z *.z *.gz *.tgz *.tar *.bz2 *(-/)' tart tarx tar
compctl -g '*.bz2 *(-/)' bz2cat bunzip2
compctl -g '*.zip *.ZIP *.exe *.EXE *(-/)' unzip
compctl -g '*.ps *.ps.gz *(-/)' gs ghostview gv evince
compctl -g '*.tex* *.latex* *(-/)' tex latex texi2dvi
compctl -g '*.dvi *(-/)' xdvi dvips
compctl -j -P % -x 's[-] p[1]' -k signals -- kill
compctl -l '' nohup exec
compctl -u -x 's[@]' -k hosts -- finger
compctl -m info
compctl -m -g '*.1 *(-/)' man
compctl -c which where type
compctl -g '*.pdf *(-/)' evince

# Hosts completion

if [ -f ~/.ssh/config ]; then
  hosts=($hosts `grep ^Host ~/.ssh/config | sed s/Host\ // | egrep -v '^\*$'`)
fi
if [ "$hosts" ]; then
  zstyle ':completion:*:hosts' hosts $hosts
fi

##########
# zstyle #
##########

zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' completions 1
zstyle ':completion:*' format 'Completing %B%d%b%:'
zstyle ':completion:*' glob 1
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' max-errors 2 numeric
zstyle ':completion:*' menu select=3
zstyle ':completion:*' prompt '%e erreur(s)...'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' substitute 1

autoload -Uz compinit
compinit

# Needed for menuselect below
zmodload zsh/complist

autoload -U incremental-complete-word
zle -N incremental-complete-word
bindkey 'i' incremental-complete-word

bindkey -M menuselect '' accept-and-infer-next-history

bindkey -s '' '/'
bindkey -s '' ','


##############################
# Source configuration files #
##############################

for rc in $ZDOTDIR/zshrc.d/??-*.zrc; do
    [[ -r ${rc} ]] && source "$rc"
done
unset rc

# Local configuration files
# (Other that zshrc, which is sourced from our zshrc.d scripts)
localrcfiles=($ZDOTLOCALDIR/??-*.zrc) 2> /dev/null
for rc in $localrcfiles; do
    [[ -r ${rc} ]] && source "$rc"
done
unset rc localrcfiles