Copyright © 2003 Nowicki Christophe
Table des matières
Introduction
Ce document explique comment activer la complétion sur les packages Debian a l'aide de 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 zshReading Package Lists... DoneBuilding Dependency Tree... DoneThe following NEW packages will be installed:zsh0 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... DonePreconfiguring 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) ...#chshChanging the login shell for rootEnter the new value, or press return for the defaultLogin 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.
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 compinstallI haven't found any existing completion definitions.If you have some already defined by compinstall, edit the name of thefile where these can be found. Note that this will only work if theyare exactly the form in which compinstall inserted them. If you leavethe line as it is, or empty, I won't search.file>/root/.zshrcStarting 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 setupsomewhere else at the end.--- Hit newline to continue or `q' to exit without saving ---d=/usr/share/zsh/4.0.7/functions/Zlecompdir=/usr/share/zsh/4.0.7/functions/Completionsubdirs=1lines=''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 fromlower level menus. However, quitting at top level will ensure thatnoting at all is actually written out.1. Completers: choose completion behaviour for tasks such asapproximation, 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 alreadyset for the context shown above. If none are selected, the completerswill 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 ---0output=''Save new settings to /root/.zshrc?ySuccessfully 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 pppppp-pam ppp-sh4-cross pppdcapiplugin pppoeconfppp-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