Article ZSH pour utilisateurs avancés

Vincent Lefevre vincent at vinc17.org
Thu Oct 26 11:31:22 CEST 2006


On 2006-10-26 11:07:43 +0200, Bruno Bonfils wrote:
> je suis en train d'écrire un article sur l'utilisation avancée de ZSH,
> si vous avez des idées de point à aborder, ou des idées de fonction de
> complétion à écrire, n'hésitez pas a m'en faire part

Voici mon fichier .zcomp, ça peut toujours être utile...

# Completion for zsh

# The following lines were added by compinstall

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _complete
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' ignore-parents parent pwd
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*'
zstyle ':completion:*' max-errors 1
zstyle ':completion:*' menu select=long
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle :compinstall filename '.zcomp'

autoload -U compinit
compinit
# End of lines added by compinstall

# Suggestion from
#   From: Peter Stephenson <pws at csr.com>
#   Date: Thu, 11 Mar 2004 12:28:17 +0000
#   Subject: Re: cd completion and CDABLE_VARS
#   To: zsh-users at sunsite.dk
#   Message-ID: <14646.1079008097 at csr.com>
#   http://www.zsh.org/mla/users/2004/msg00150.html
# to disable named directories in the first completion choices.
zstyle ':completion:*:complete:(cd|pushd):*' tag-order \
  'local-directories path-directories directory-stack' '*'

# When starting to type a command, avoid the completion on directories
# (and executables in the cwd), e.g. avoid the following:
#   prunille:~> imdb[TAB]
#   Completing external command
#   Completing executable file or directory
#   imdb/     imdbinfo
# where imdbinfo is an external command (in $path).
zstyle ':completion:*:complete:-command-:*' tag-order 'commands builtins functions aliases suffix-aliases reserved-words jobs parameters' '*'
# This only works if the directory (here, imdb) is in the cwd,
# but not if it is in another directory of the cdpath. :(

compdef latexn=latex

# Suggestion from
#   From: Bart Schaefer <schaefer at brasslantern.com>
#   Date: Wed, 21 Jul 2004 17:32:36 -0700 (PDT)
#   Subject: Re: TAB at the command line beginning
#   To: Zsh Mailinglist <zsh-users at sunsite.dk>
#   Message-ID: <Pine.LNX.4.61.0407211649070.20062 at toltec.zanshin.com>
#   http://www.zsh.org/mla/users/2004/msg00743.html
history-search-or-expand-or-complete()
{
  if [[ -z "$BUFFER" && -z "$PREBUFFER" ]] then
    zle history-incremental-search-backward "$@"
  else
    zle expand-or-complete "$@"
  fi
}
zle -N history-search-or-expand-or-complete
bindkey '\t' history-search-or-expand-or-complete

# Suggestion from
#   From: Bart Schaefer <schaefer at brasslantern.com>
#   Date: Thu, 19 Aug 2004 10:16:10 -0700 (PDT)
#   Subject: Re: Tip of the day: previous command output
#   To: Zsh-users List <zsh-users at sunsite.dk>
#   Message-ID: <Pine.LNX.4.61.0408190956440.9464 at toltec.zanshin.com>
#   http://www.zsh.org/mla/users/2004/msg00896.html
# and following messages...
keep()
{
  kept=()
  kept=( $~* )
  if [[ ! -t 0 ]] then
    while read line; do
      kept+=( $line )
    done
  fi
  print -Rc - $kept
}
alias keep='noglob keep '

_insert_kept()
{
  (( $#kept )) || return 1
  local action
  zstyle -s :completion:$curcontext insert-kept action
  [[ -n $action ]] && compstate[insert]=$action
  compadd -a kept
}
zle -C insert-kept-result complete-word _generic
zstyle ':completion:insert-kept-result:*' completer _insert_kept
zstyle ':completion:*' insert-kept all
bindkey '\e\t' insert-kept-result

# Suggestion from the manual and
#   From: Bart Schaefer <schaefer at brasslantern.com>
#   Date: Sat, 19 Aug 2006 20:16:27 -0700
#   Subject: Re: How to insert completions on command line
#   To: zsh-users at sunsite.dk
#   Message-id: <060819201627.ZM28979 at torch.brasslantern.com>
#   http://www.zsh.org/mla/users/2006/msg00820.html
zle -C all-matches complete-word _generic
bindkey '^X\t' all-matches
zstyle ':completion:all-matches:*' insert yes
zstyle ':completion:all-matches::::' completer _all_matches _complete

# Note: interesting information can be obtained with _complete_help (^Xh).

# $Id: zcomp 14359 2006-10-12 22:44:51Z lefevre $

-- 
Vincent Lefèvre <vincent at vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


More information about the Shell mailing list