27juil. 2005
Configuration Zsh
15:14 - Par Great A'Tan - GNU/Linux, Logiciels Libres et autres Geekeries - aucun commentaire
Zsh est un shell extrêmement puissant pour linux. J'utilisais jusqu'alors bash, mais vu les limites des commandes offertes, je suis passé à zsh. Et il y a beaucoup de temps à passer à configurer le comportement de ce shell. Je vais donc donner ma configuration
################################################################################ ################################################################################ # .zshrc file for zsh 4.0 # ################################################################################ ################################################################################ ################################################################################ # Shell Functions # ################################################################################ # This function automatically create a compressed (tar.gz) version of the # give directory, named with date of creation. backup_dir() { dir=$1 tarfile=$1-$date.tar.gz echo "Creating $tarfile..." tar cfvz $tarfile $1/ echo "Done." } setenv() # csh compatibility { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } freload() { while (( $# )); do ; unfunction $1; autoload -U $1; shift; done } # This function is called just before printing a new prompt # Using it to change the title bar of the current terminal precmd () { # print the username@host: path print -Pn "e]0;%n@%m: %~a" } # Same but before executing a command preexec () { # print username@host: path <executed app> # print -Pn "e]0;%n@%m: $~a" print -Pn "e]0;%n@%m: %~ < ${(Vq)2}>a" } ################################################################################ # Search, function and man Pathes and environment variables # ################################################################################ # Search path for the cd command cdpath=(.. ~ ~/src ~/zsh) # Where to look for autoloaded function definitions # fpath=($fpath ~/.zfunc) # Autoload all shell functions from all directories in $fpath (following # symlinks) that have the executable bit on (the executable bit is not # necessary, but gives you an easy way to stop the autoloading of a # particular shell function). $fpath should not be empty for this to work. # for func in $^fpath/*(N-.x:t); autoload $func # automatically remove duplicates from these arrays typeset -U path cdpath fpath manpath manpath=(/usr/X11R6/man /usr/man /usr/share/man /usr/local/man ) export MANPATH # less is my preferred pager export PAGER=less LESS=-cex3M # Extensions to ignore for completion. FIGNORE=".o:~" HISTFILE="$HOME/.zsh_hist" # Remember the last 5000 commands. HISTSIZE=5000 # Save the last 3000 commands. SAVEHIST=3000 DIRSTACKSIZE=20 # Never look at my mail spool. MAILCHECK=0 # Give timing statistics for programs that take longer than a minute to # run. REPORTTIME=60 export LD_LIBRARY_PATH=/local/local/lib:$LD_LIBRARY_PATH export PATH=/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/home/gsem01/scripts:$PATH ################################################################################ # Limites configuration # ################################################################################ ulimit > /dev/null ulimit -s > /dev/null umask 022 ################################################################################ # Color and prompt (and all visual stuffs) # ################################################################################ eval `dircolors -b` zmodload -i zsh/complist export ZLSCOLORS="${LS_COLORS}" # Beautiful prompt hosts=(`hostname`) autoload -U colors colors host_color="green" path_color="blue" date_color="yellow" date_format="%H:%M" date="%{fg[$date_color]%}%D{date_format}" userhost="%{$fg[yellow]%}[%B%{$fg[green]%}%n%b%{$fg[yellow]%}@%B%{$fg[red]%}%m%b%{$fg[yellow]%}]" cpath="%B%{$fg[cyan]%}%35< ...<%~%b%{$fg[yellow]%}" delimchar="%{$fg[yellow]%}%# " end="%{$reset_color%}" returncmd="%{$fg[yellow]%}[%{$fg[cyan]%}%?%{$fg[yellow]%}]" # Main prompt PS1="$userhost$cpath$returncmd$delimchar$end" # Right Prompt => date RPS1="%{$fg[yellow]%}[%{$fg[white]%}%(t.Ding!.%B%D{%T}%b)%{$fg[yellow]%}]$end" ################################################################################ # Aliases # ################################################################################ # import aliases [ -f ~/.alias ]; source ~/.alias # Global aliases -- These do not have to be # at the beginning of the command line. alias -g M='|more' alias -g L='|less' alias -g H='|head' alias -g T='|tail' alias -g ...='../..' alias -g ....='../../..' alias -g .....='../../../..' # zsh specific aliases alias mkdir='nocorrect mkdir' ################################################################################ # Zsh shell options # ################################################################################ setopt notify globdots correct pushdtohome cdablevars autolist setopt correctall autocd recexact longlistjobs setopt autoresume histignoredups pushdsilent noclobber setopt autopushd pushdminus extendedglob rcquotes mailwarning unsetopt bgnice autoparamslash setopt c_bases # Print hex numbers like 0x7F instead of 16#7Fs setopt hist_save_no_dups # Only the newest of a set of duplicates (regardless of # sequence) is saved to file setopt inc_append_history # Commands are added to the history file as they are # entered. setopt list_packed # Use variable width columns for completion options setopt octal_zeroes # print octal numbers like 037 instead of 8#37 # Autoload zsh modules when they are referenced zmodload -a zsh/stat stat zmodload -a zsh/zpty zpty zmodload -a zsh/zprof zprof zmodload -ap zsh/mapfile mapfile ################################################################################ # Overwrite default bind keys # ################################################################################ bindkey ' ' magic-space # also do history expansion on space bindkey '^I' complete-word # complete on tab, leave expansion to _expand bindkey "^[[7~" beginning-of-line # Home bindkey "^[[8~" end-of-line # End bindkey "^[[2~" overwrite-mode # insert bindkey "^[[3~" delete-char # delete bindkey "^H" backward-delete-char #backspace bindkey "^[[H" backward-delete-char #backspace bindkey '^[Od' backward-word bindkey '^[^[[D' backward-word bindkey '^[Oc' forward-word bindkey '^[^[[C' forward-word ################################################################################ # Completion options # ################################################################################ # Setup new style completion system. To see examples of the old style (compctl # based) programmable completion, check Misc/compctl-examples in the zsh # distribution. autoload -U compinit compinit -i # silenty ignone insecure directory and file ZLS_COLORS=$LS_COLORS # Completion Styles # Add a menu on completion zstyle ':completion:*' menu select=1 zstyle ':completion:*' completer _complete _prefix zstyle ':completion::prefix-1:*' completer _complete zstyle ':completion:incremental:*' completer _complete _correct zstyle ':completion:predict:*' completer _complete zstyle ':completion::complete:*' use-cache 1 zstyle ':completion::complete:*' cache-path ~/.zshcache zstyle ':completion:*' expand 'yes' zstyle ':completion:*' squeeze-slashes 'yes' zstyle ':completion::complete:*' '' # Use menuselection for pid completion zstyle ':completion:*:*:kill:*' menu yes select zstyle ':completion:*:kill:*' force-list always # tag-order 'globbed-files directories' all-files zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)' # Don't complete backup files as executables zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*~' # Separate matches into groups zstyle ':completion:*:matches' group 'yes' # With commands like rm, it's annoying if you keep getting offered the same # file multiple times. This fixes it. Also good for cp, et cetera.. zstyle ':completion:*:rm:*' ignore-line yes zstyle ':completion:*:cp:*' ignore-line yes # Describe each match group. zstyle ':completion:*:descriptions' format "%{$fg_bold[blue]%}[ %{$fg_bold[green]%}%d%{$fg_bold[blue]%}]%{$reset_color%}" # Messages/warnings format zstyle ':completion:*:messages' format "%{$fg_bold[blue]%}[ %{$fg_bold[yellow]%}%d%{$fg_bold[blue]%}]%{$reset_color%}" zstyle ':completion:*:warnings' format "%{$fg_bold[blue]%}[ %{$fg_bold[red]%}No match for %d%{$fg_bold[blue]%}]%{$reset_color%}" # Describe options in full zstyle ':completion:*:options' description 'yes' zstyle ':completion:*:options' auto-description '%d' # Simulate spider's old abbrev-expand 3.0.5 patch zstyle ':completion:*:history-words' stop verbose zstyle ':completion:*:history-words' remove-all-dups yes zstyle ':completion:*:history-words' list false # Follow GNU LS_COLORS zmodload -i zsh/complist # allow one error for every three characters typed in approximate completer zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )' # insert all expansions for expand completer zstyle ':completion:*:expand:*' tag-order all-expansions # formatting and messages zstyle ':completion:*' verbose yes zstyle ':completion:*:descriptions' format '%B%d%b' zstyle ':completion:*:messages' format '%d' zstyle ':completion:*:warnings' format 'No matches for: %d' zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b' zstyle ':completion:*' group-name '' # match uppercase from lowercase zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # offer indexes before parameters in subscripts zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters # command for process lists, the local web server details and host completion zstyle ':completion:*:processes' command 'ps -o pid,s,nice,stime,args' #zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html' zstyle '*' hosts $hosts # Filename suffixes to ignore during completion (except after rm command) zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.old' '*?.pro' # the same for old style completion #fignore=(.o .c~ .old .pro) # ignore completion functions (until the _ignored completer) zstyle ':completion:*:functions' ignored-patterns '_*' # auto complete with local directories zstyle ':completion:*:*:cd:*' tag-order local-directories path-directories ################################################################################ # Last command to execute # ################################################################################ # cd into work directory [ -f ~/local/work/ ] && cd ~/local/work/ 2> /dev/null
aucun commentaire