Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Unify apt releases handling for apt and aptitude completion.



The aptitude completion was slightly broken, as it didn't
consider /etc/apt/sources.list.d/*, so just use the same
completion for apt and aptitude.
---
 Completion/Debian/Command/_apt       | 35 ---------------------------------
 Completion/Debian/Command/_aptitude  | 13 +-----------
 Completion/Debian/Type/_apt_releases | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 47 deletions(-)
 create mode 100644 Completion/Debian/Type/_apt_releases

diff --git a/Completion/Debian/Command/_apt b/Completion/Debian/Command/_apt
index b51b2fc..d656303 100644
--- a/Completion/Debian/Command/_apt
+++ b/Completion/Debian/Command/_apt
@@ -551,39 +551,4 @@ _apt-config () {
   _apt-config "$@"
 }
 
-_apt_releases_update () {
-  if ( [[ ${+_apt_releases} -eq 0 ]] ||
-      _cache_invalid APT_releases ) && ! _retrieve_cache APT_releases;
-  then
-    _apt_releases=(
-${${${${(M)${(f)"$(apt-cache policy)"}:#*release*}#*a=}%%,*}:#now}
-    )
-    typeset -U _apt_releases
-    _store_cache APT_releases _apt_releases
-  fi
-}
-
-_apt_releases () {
-  local update_policy
-
-  zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
-  if [[ -z "$update_policy" ]]; then
-    zstyle ":completion:*:*:$service:*" cache-policy _apt_caching_policy
-  fi
-
-  _apt_releases_update
-
-  _tags apt-releases && compadd -a _apt_releases
-}
-
-_apt_caching_policy () {
-  local -a oldp
-
-  oldp=( "$1"(mw+1) )
-  (( $#oldp )) && return 0
-
-  [[ /var/cache/apt/pkgcache.bin -nt "$1" ||
-     /var/lib/dpkg/available -nt "$1" ]]
-}
-
 _apt "$@"
diff --git a/Completion/Debian/Command/_aptitude b/Completion/Debian/Command/_aptitude
index 2c462e4..ae89ad2 100644
--- a/Completion/Debian/Command/_aptitude
+++ b/Completion/Debian/Command/_aptitude
@@ -2,17 +2,6 @@
 
 local curcontext="$curcontext" state line cmds ret=1
 
-function _aptitude_release() {
-  #{{{
-  local expl releases
-  releases=(
-${${(M)${(f)"$(</etc/apt/sources.list)"}\
-:#[ $'\t']#deb(|-src)*}/(#b)[ $'\t']#[^ $'\t']##[ $'\t']##[^ $'\t']##[ $'\t']##([^ $'\t']##)*/$match[1]}
-  )
-  _wanted list expl release compadd ${expl} - ${(u)releases}
-  #}}}
-}
-
 # Helper function for -F / --display-format
 function _aptitude_format_strings() {
   _values -s , 'format string' \
@@ -65,7 +54,7 @@ _arguments -C \
   '(--without-suggests)--with-suggests[install suggested packages when installing new packages]' \
   '(-r --with-recommends)'{-r,--without-recommends}'[ignore recommended packages when installing new packages]' \
   '(--with-suggests)--without-suggests[ignore suggested packages when installing new packages]' \
-  '(-t --target-release)'{-t,--target-release}'[set the release from which packages should be installed]:release:_aptitude_release' \
+  '(-t --target-release)'{-t,--target-release}'[set the release from which packages should be installed]:release:_apt_releases' \
   '(-q --quiet)'{-q=,--quiet=}'[less Output]:level' \
   '--schedule-only[schedule operations to be performed in the future]' \
   '--purge-unused[purge unused packages instead of removing]' \
diff --git a/Completion/Debian/Type/_apt_releases b/Completion/Debian/Type/_apt_releases
new file mode 100644
index 0000000..26bc40b
--- /dev/null
+++ b/Completion/Debian/Type/_apt_releases
@@ -0,0 +1,38 @@
+#autoload
+
+_apt_releases_update () {
+  if ( [[ ${+_apt_releases} -eq 0 ]] ||
+      _cache_invalid APT_releases ) && ! _retrieve_cache APT_releases;
+  then
+    _apt_releases=(
+${${${${(M)${(f)"$(apt-cache policy)"}:#*release*}#*a=}%%,*}:#now}
+    )
+    typeset -U _apt_releases
+    _store_cache APT_releases _apt_releases
+  fi
+}
+
+_apt_releases () {
+  local update_policy
+
+  zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
+  if [[ -z "$update_policy" ]]; then
+    zstyle ":completion:*:*:$service:*" cache-policy _apt_caching_policy
+  fi
+
+  _apt_releases_update
+
+  _tags apt-releases && compadd -a _apt_releases
+}
+
+_apt_caching_policy () {
+  local -a oldp
+
+  oldp=( "$1"(mw+1) )
+  (( $#oldp )) && return 0
+
+  [[ /var/cache/apt/pkgcache.bin -nt "$1" ||
+     /var/lib/dpkg/available -nt "$1" ]]
+}
+
+_apt_releases "@"
-- 
1.8.4.rc3



Messages sorted by: Reverse Date, Date, Thread, Author