From 5f37649508f6b6323e78249671d7897af8076886 Mon Sep 17 00:00:00 2001 From: mapc Date: Sat, 30 Jun 2012 04:44:26 +0200 Subject: [PATCH] Dynamicly generate completion functions to support changing apt_pref --- plugins/debian/debian.plugin.zsh | 45 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index c556cb0b5..b6f9fd2bf 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -110,18 +110,39 @@ fi # Completion ################################################################ -# TODO: These definitions won't change between apt-get and uptitude automaticaly -compdef _apt aac="$apt_pref autoclean" -compdef _apt abd="$apt_pref build-dep" -compdef _apt ac="$apt_pref clean" -compdef _apt ad="$apt_pref update" -compdef _apt afu="$apt_pref update" -compdef _apt ag="$apt_pref upgrade" -compdef _apt ai="$apt_pref install" -compdef _apt ail="$apt_pref install" -compdef _apt ap="$apt_pref purge" -compdef _apt ar="$apt_pref remove" -compdef _apt ads="apt-get dselect-upgrade" +# +# Registers a compdef for $1 that calls $apt_pref with the commands $2 +# To do that it creates a new completion function called _apt_pref_$2 +# +apt_pref_compdef() { + local f fb + f="_apt_pref_${2}" + + fb="function ${f}() { + shift words; + service=\"\$apt_pref\"; + words=(\"\$apt_pref\" '$2' \$words); + ((CURRENT++)) + test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt + }" + + eval "$fb" + echo "$fb" + + compdef "$f" "$1" +} + +apt_pref_compdef aac "autoclean" +apt_pref_compdef abd "build-dep" +apt_pref_compdef ac "clean" +apt_pref_compdef ad "update" +apt_pref_compdef afu "update" +apt_pref_compdef ag "upgrade" +apt_pref_compdef ai "install" +apt_pref_compdef ail "install" +apt_pref_compdef ap "purge" +apt_pref_compdef ar "remove" +apt_pref_compdef ads "dselect-upgrade" # Misc. ##################################################################### # print all installed packages