Activer la complétion sur les packages Debian avec Zsh

Nowicki Christophe

Permission est accordée de copier, distribuer et/ou modifier ce document selon les termes de la Licence de Documentation Libre GNU (GNU Free Documentation License), version 1.1 ou toute version ultérieure publiée par la Free Software Foundation. Pas de section inaltérable.


Table des matières

Installer Zsh
Activer la complétion

Introduction

Ce document explique comment activer la complétion sur les packages Debian a l'aide de Zsh.

Installer Zsh

Nous allons installer Zsh avec l'aide d'apt et changer le shell par default de l'utilisateur root.

  #echo $SHELL
  /bin/bash
  #apt-get install zsh
  Reading Package Lists... Done
  Building Dependency Tree... Done
  The following NEW packages will be installed:
    zsh
  0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  Need to get 1676kB of archives.
  After unpacking 4985kB of additional disk space will be used.
  Get:1 http://192.168.0.1 unstable/main zsh 4.0.7-5 [1676kB]
  Fetched 1676kB in 0s (4041kB/s)
  Reading changelogs... Done
  Preconfiguring packages ...
  Selecting previously deselected package zsh.
  (Reading database ... 150836 files and directories currently installed.)
  Unpacking zsh (from .../archives/zsh_4.0.7-5_i386.deb) ...
  Setting up zsh (4.0.7-5) ...
  #chsh
  Changing the login shell for root
  Enter the new value, or press return for the default
          Login Shell
  [/bin/bash]:/bin/zsh
  #su -
  #echo $SHELL
  /bin/zsh
  

Voila le login shell de l'utilisateur root est Zsh. Il ne nous reste plus qu'à activer la complétion de celui-ci.

Activer la complétion

Par default la complétion de zsh n'est pas activée. Il faut donc modifier le fichier .zshrc dans le repertoire de l'utilisateur, ou bien dans le fichier /etc/zshrc. Le script Zsh compinstall automatise l'activation de la complétion. Il se trouve dans le répertoire /usr/share/zsh/<VERSION DE ZSH>/functions/Completion par default sur Debian GNU/Linux.

  #cd /usr/share/zsh/4.0.7/functions/Completion
  #source compinstall
  I haven't found any existing completion definitions.
  If you have some already defined by compinstall, edit the name of the
  file where these can be found.  Note that this will only work if they
  are exactly the form in which compinstall inserted them.  If you leave
  the line as it is, or empty, I won't search.
  file>/root/.zshrc
  Starting a new completion configuration from scratch.
  This will be written to the new file /root/.zshrc.
  Note that you will be given a chance to save the new setup
  somewhere else at the end.
  --- Hit newline to continue or `q' to exit without saving ---
  
  d=/usr/share/zsh/4.0.7/functions/Zle
  compdir=/usr/share/zsh/4.0.7/functions/Completion
  subdirs=1
  lines=''
  Completion directories /usr/share/zsh/4.0.7/functions/Completion/*
  are already in your $fpath, good.
  --- Hit newline to continue or `q' to exit without saving --- 
  

                 *** compinstall: main menu ***
Note that hitting `q' in menus does not abort the set of changes from
lower level menus.  However, quitting at top level will ensure that
noting at all is actually written out.

1.  Completers:  choose completion behaviour for tasks such as
    approximation, spell-checking, expansion.

2.  Matching control: set behaviour for case-insensitive matching,
    extended (partial-word) matching and substring matching.

3.  Styles for changing the way completions are displayed and inserted.

4.  Styles for particular completions.

c.  Change context (plus more information on contexts).

q.  Return without saving.
0.  Save and exit.

--- Hit choice ---
 

Nous allons configurer les modules de complétion à l'aide de l'option 1 du menu.

              *** compinstall: completer menu ***

Current context: :completion:*

The following completers are available.  Those marked `(*)' are already
set for the context shown above.  If none are selected, the completers
will not be set for this context at all.

1. (*) Basic completion.
2. (*) Approximate completion:  completion with correction of existing word.
3. (*) Correction:  correct existing word, no completion.
4. (*) Expansion: use globbing and parameter substitution, if possible.

o.     Set options for the completers above.
m.     Set completers that modify the behaviour of the four main ones above.
q.     Return without saving.
0.     Done setting completers.

--- Hit selection --- 
  

Pour avoir la complétion sur les packages, il suffit de choisir "Basic completion". Après avoir choisi le comportement de Zsh, il faut retourner au menu principal à l'aide de la touche "0". Et sauvegarder son choix par cette même touche "0".

  --- Hit choice --- 0
  output=''
  Save new settings to /root/.zshrc? y
  
  Successfully added compinstall lines to /root/.zshrc.
  Set new styles for immediate use?n
  

Zsh doit etre relancé pour que la nouvelle configuration soit prise en compte.

  #zsh
  #apt-get install ppp
  ppp-pam          ppp-sh4-cross    pppdcapiplugin   pppoeconf
  ppp-sh3-cross    ppp-udeb         pppoe            pppstatus
  

Comme vous pouvez le voir, Zsh complete tout les packages qui commencent par ppp et qui ne sont pas installé sur mon systeme. Il peut effectuer des complétions sur beaucoups d'autres choses. Mais je vous laisse le découvrir par vous meme.

Un dernière petite precision a propos du script compinstall. Celui-ci ajoute les lignes suivantes dans le fichier /root/.zshrc

# The following lines were added by compinstall

zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle :compinstall filename '/root/.zshrc'

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

Le script compinstall se trouve dans le PATH de Zsh, et il est possible de modifier le comportement du compléteur a n'importe quel moment. Vous pouvez copier le fichier de configuration .zshrc de l'utilisateur root dans le fichier de configuration global de Zsh pour que chaque utilisateur qui l'utilise beneficie de la complétion.

  #cp /root/.zshrc /etc/zsh/zshrc