5f37649508f6b6323e78249671d7897af8076886

Author
mapc <musikmichael@web.de>
Committer
mapc <musikmichael@web.de>
Date

Message

Dynamicly generate completion functions to support changing apt_pref

Diff

 1diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh
 2index c556cb0b59dc2ec0b80844d3b7578ae6ab7a4974..b6f9fd2bf5d9571b968639f907dc9f70e60b256d 100644
 3--- a/plugins/debian/debian.plugin.zsh
 4+++ b/plugins/debian/debian.plugin.zsh
 5@@ -110,18 +110,39 @@ fi
 6 
 7 # Completion ################################################################
 8 
 9-# TODO: These definitions won't change between apt-get and uptitude automaticaly
10-compdef _apt aac="$apt_pref autoclean"
11-compdef _apt abd="$apt_pref build-dep"
12-compdef _apt ac="$apt_pref clean"
13-compdef _apt ad="$apt_pref update"
14-compdef _apt afu="$apt_pref update"
15-compdef _apt ag="$apt_pref upgrade"
16-compdef _apt ai="$apt_pref install"
17-compdef _apt ail="$apt_pref install"
18-compdef _apt ap="$apt_pref purge"
19-compdef _apt ar="$apt_pref remove"
20-compdef _apt ads="apt-get dselect-upgrade"
21+#
22+# Registers a compdef for $1 that calls $apt_pref with the commands $2
23+# To do that it creates a new completion function called _apt_pref_$2
24+#
25+apt_pref_compdef() {
26+    local f fb
27+    f="_apt_pref_${2}"
28+
29+    fb="function ${f}() {
30+        shift words; 
31+	service=\"\$apt_pref\"; 
32+	words=(\"\$apt_pref\" '$2' \$words); 
33+	((CURRENT++))
34+	test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt
35+    }"
36+    
37+    eval "$fb"
38+    echo "$fb"
39+
40+    compdef "$f" "$1"
41+}
42+
43+apt_pref_compdef aac "autoclean"
44+apt_pref_compdef abd "build-dep"
45+apt_pref_compdef ac  "clean"
46+apt_pref_compdef ad  "update"
47+apt_pref_compdef afu "update"
48+apt_pref_compdef ag  "upgrade"
49+apt_pref_compdef ai  "install"
50+apt_pref_compdef ail "install"
51+apt_pref_compdef ap  "purge"
52+apt_pref_compdef ar  "remove"
53+apt_pref_compdef ads "dselect-upgrade"
54 
55 # Misc. #####################################################################
56 # print all installed packages