zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: _apt-get and _deb_packages
@ 1999-09-02 21:14 Tanaka Akira
  1999-09-03 20:30 ` Falk Hueffner
  0 siblings, 1 reply; 5+ messages in thread
From: Tanaka Akira @ 1999-09-02 21:14 UTC (permalink / raw)
  To: zsh-workers

This is completion functions for apt-get of Debian.

--- /dev/null	Fri Sep  3 02:54:25 1999
+++ Completion/Debian/_apt-get	Fri Sep  3 05:47:52 1999
@@ -0,0 +1,23 @@
+#compdef apt-get
+
+_arguments -s \
+  -{,-no-}d --{,no-}download-only \
+  -{,-no-}f --{,no-}fix-broken \
+  -{,-no-}h --{,no-}help \
+  -{,-no-}v --{,no-}version \
+  -{,-no-}m --{,no-}ignore-missing \
+  --{,no-}fix-missing \
+  --{,no-}no-download \
+  \*-{,-no-}q \*--{,no-}{quiet,silent} \
+  -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \
+  -{,-no-}y --{,no-}{yes,assume-yes} \
+  -{,-no-}u --{,no-}show-upgraded \
+  -{,-no-}b --{,no-}{compile,build} \
+  --{,no-}ignore-hold \
+  --{,no-}no-upgrade \
+  --{,no-}force-yes \
+  --{,no-}print-uris \
+  {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \
+  {-o,--option}':Foo\:\:Bar=bar:' \
+  ':command:(update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help)' \
+  '*:package:_deb_packages'
--- /dev/null	Fri Sep  3 02:54:25 1999
+++ Completion/Debian/_deb_packages	Fri Sep  3 06:11:01 1999
@@ -0,0 +1,7 @@
+#autoload
+
+if (( ! $+_deb_packages )); then
+  _deb_packages=( $(awk '/^Package:/ { print $2 }' /var/lib/dpkg/status) )
+fi
+
+compadd "$@" - $_deb_packages
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: _apt-get and _deb_packages
  1999-09-02 21:14 PATCH: _apt-get and _deb_packages Tanaka Akira
@ 1999-09-03 20:30 ` Falk Hueffner
  1999-09-03 23:17   ` Tanaka Akira
  1999-09-04 14:49   ` Clint Adams
  0 siblings, 2 replies; 5+ messages in thread
From: Falk Hueffner @ 1999-09-03 20:30 UTC (permalink / raw)
  To: zsh-workers

Tanaka Akira <akr@jaist.ac.jp> writes:

> This is completion functions for apt-get of Debian.

Thanks, this is a good idea.

It would be nice if after 'install' only uninstalled packages would be
completed, and after 'remove' and 'purge' only installed.

A way to get installed packages is

dpkg --get-selections | awk '/[^e]install$/ { print $1 }'

Another problem is that when using the "apt" tool, dpkg might not know 
about some available packages. Perhaps a better way of getting
available packages is

apt-cache dumpavail |  awk '/^Package:/ { print $2 }'

Perhaps there is an easy way of making a set difference to get a list
of uninstalled packages.

Unfortunately, I haven't yet looked enough at the new completion
system to help you further...

	Falk


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: _apt-get and _deb_packages
  1999-09-03 20:30 ` Falk Hueffner
@ 1999-09-03 23:17   ` Tanaka Akira
  1999-09-04 14:49   ` Clint Adams
  1 sibling, 0 replies; 5+ messages in thread
From: Tanaka Akira @ 1999-09-03 23:17 UTC (permalink / raw)
  To: zsh-workers

In article <87u2pbu49r.fsf@zxmjz18.extern.uni-tuebingen.de>,
  Falk Hueffner <falk.hueffner@student.uni-tuebingen.de> writes:

> It would be nice if after 'install' only uninstalled packages would be
> completed, and after 'remove' and 'purge' only installed.

What's `purge'?
At least, the manual in apt 0.3.11 doesn't mention the command.

> dpkg --get-selections | awk '/[^e]install$/ { print $1 }'

> apt-cache dumpavail |  awk '/^Package:/ { print $2 }'

I see. Thanks.

Index: Completion/Debian/_apt-get
===================================================================
RCS file: /projects/zsh/zsh/Completion/Debian/_apt-get,v
retrieving revision 1.1.1.1
diff -u -F^( -r1.1.1.1 _apt-get
--- _apt-get	1999/09/02 21:27:08	1.1.1.1
+++ _apt-get	1999/09/03 23:05:44
@@ -1,23 +1,40 @@
 #compdef apt-get
 
-_arguments -s \
-  -{,-no-}d --{,no-}download-only \
-  -{,-no-}f --{,no-}fix-broken \
-  -{,-no-}h --{,no-}help \
-  -{,-no-}v --{,no-}version \
-  -{,-no-}m --{,no-}ignore-missing \
-  --{,no-}fix-missing \
-  --{,no-}no-download \
-  \*-{,-no-}q \*--{,no-}{quiet,silent} \
-  -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \
-  -{,-no-}y --{,no-}{yes,assume-yes} \
-  -{,-no-}u --{,no-}show-upgraded \
-  -{,-no-}b --{,no-}{compile,build} \
-  --{,no-}ignore-hold \
-  --{,no-}no-upgrade \
-  --{,no-}force-yes \
-  --{,no-}print-uris \
-  {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \
-  {-o,--option}':Foo\:\:Bar=bar:' \
-  ':command:(update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help)' \
-  '*:package:_deb_packages'
+_apt-get () {
+  # This doesn't handle command line of apt completely since command line
+  # parsing library for apt is too complex to handle by _arguments.
+  _arguments -s \
+    -{,-no-}d --{,no-}download-only \
+    -{,-no-}f --{,no-}fix-broken \
+    -{,-no-}h --{,no-}help \
+    -{,-no-}v --{,no-}version \
+    -{,-no-}m --{,no-}ignore-missing \
+    --{,no-}fix-missing \
+    --{,no-}no-download \
+    \*-{,-no-}q \*--{,no-}{quiet,silent} \
+    -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \
+    -{,-no-}y --{,no-}{yes,assume-yes} \
+    -{,-no-}u --{,no-}show-upgraded \
+    -{,-no-}b --{,no-}{compile,build} \
+    --{,no-}ignore-hold \
+    --{,no-}no-upgrade \
+    --{,no-}force-yes \
+    --{,no-}print-uris \
+    {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \
+    {-o,--option}':Foo\:\:Bar=bar:' \
+    '*::command and packages:_apt-get_args'
+}
+
+_apt-get_args () {
+  if (( CURRENT == 1 )); then
+    compadd "$@" - update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help
+  else
+    case "$words[1]" in
+      install) _deb_packages uninstalled "$@";;
+      remove) _deb_packages installed "$@";;
+      *) _deb_packages avail "$@";;
+    esac
+  fi
+}
+
+_apt-get "$@"
Index: Completion/Debian/_deb_packages
===================================================================
RCS file: /projects/zsh/zsh/Completion/Debian/_deb_packages,v
retrieving revision 1.1.1.1
diff -u -F^( -r1.1.1.1 _deb_packages
--- _deb_packages	1999/09/02 21:27:08	1.1.1.1
+++ _deb_packages	1999/09/03 23:05:44
@@ -1,7 +1,27 @@
 #autoload
 
-if (( ! $+_deb_packages )); then
-  _deb_packages=( $(awk '/^Package:/ { print $2 }' /var/lib/dpkg/status) )
+# Usage: _deb_packages installed|uninstalled|avail
+
+if (( ! $+_deb_cache_dpkg_get_selections )); then
+  _deb_cache_dpkg_get_selections=(
+    ${(f)"$(dpkg --get-selections)"}
+  )
+  _deb_cache_avail=(
+    ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"}
+  )
+  _deb_cache_installed=(
+    ${${_deb_cache_dpkg_get_selections:#*deinstall}%%	*}
+  )
+  _deb_cache_uninstalled=(
+    ${_deb_cache_avail:#${(j:|:)~${_deb_cache_installed:q}}}
+  )
 fi
+
+local command="$1"
+shift
 
-compadd "$@" - $_deb_packages
+case "$command" in
+  installed) compadd "$@" - $_deb_cache_installed;;
+  uninstalled) compadd "$@" - $_deb_cache_uninstalled;;
+  avail) compadd "$@" - $_deb_cache_avail;;
+esac
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: _apt-get and _deb_packages
  1999-09-03 20:30 ` Falk Hueffner
  1999-09-03 23:17   ` Tanaka Akira
@ 1999-09-04 14:49   ` Clint Adams
  1999-09-05 15:08     ` Tanaka Akira
  1 sibling, 1 reply; 5+ messages in thread
From: Clint Adams @ 1999-09-04 14:49 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: zsh-workers

> It would be nice if after 'install' only uninstalled packages would be

I don't think so.  I frequently use 'install' to upgrade a set of
packages that are already installed.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: _apt-get and _deb_packages
  1999-09-04 14:49   ` Clint Adams
@ 1999-09-05 15:08     ` Tanaka Akira
  0 siblings, 0 replies; 5+ messages in thread
From: Tanaka Akira @ 1999-09-05 15:08 UTC (permalink / raw)
  To: zsh-workers

In article <19990904104942.B17943@dman.com>,
  Clint Adams <schizo@debian.org> writes:

> I don't think so.  I frequently use 'install' to upgrade a set of
> packages that are already installed.

Hm. I modified _apt-get to complete installed packages if current word
doesn't match uninstalled packages.

Index: Completion/Debian/_apt-get
===================================================================
RCS file: /projects/zsh/zsh/Completion/Debian/_apt-get,v
retrieving revision 1.1.1.2
diff -u -F^( -r1.1.1.2 _apt-get
--- _apt-get	1999/09/03 23:19:14	1.1.1.2
+++ _apt-get	1999/09/05 15:06:12
@@ -30,7 +30,7 @@
     compadd "$@" - update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help
   else
     case "$words[1]" in
-      install) _deb_packages uninstalled "$@";;
+      install) _deb_packages uninstalled "$@" || _deb_packages installed "$@";;
       remove) _deb_packages installed "$@";;
       *) _deb_packages avail "$@";;
     esac
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1999-09-05 15:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-02 21:14 PATCH: _apt-get and _deb_packages Tanaka Akira
1999-09-03 20:30 ` Falk Hueffner
1999-09-03 23:17   ` Tanaka Akira
1999-09-04 14:49   ` Clint Adams
1999-09-05 15:08     ` Tanaka Akira

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).