zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: new completions
@ 2004-01-14 16:58 Oliver Kiddle
  2004-01-15  7:33 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Oliver Kiddle @ 2004-01-14 16:58 UTC (permalink / raw)
  To: Zsh workers

Just a couple of new completion functions.

Index: Completion/Unix/Command/_getent
===================================================================
RCS file: Completion/Unix/Command/_getent
diff -N Completion/Unix/Command/_getent
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Command/_getent	14 Jan 2004 16:51:24 -0000
@@ -0,0 +1,50 @@
+#compdef getent
+
+local curcontext="$curcontext" state line expl ret=1
+local services databases keys
+local -a args
+typeset -A opt_args
+
+if _pick_variant -r is_gnu gnu=GNU unix --version; then
+  args+=(
+    '(- 1 *)'{-\?,--help}'[display help information]'
+    '(- 1 *)--usage[display a short usage message]'
+    '(- 1 *)'{-V,--version}'[display version information]'
+    {-s,--service=}'[specify service configuration to use]:service:->services'
+  )
+fi
+
+_arguments -C "$args[@]" \
+  '1:database:->databases' \
+  '*:key:->keys' && ret=0
+
+case $state in
+  services)
+    services=( /lib/libnss*(-.:fr:t:s/libnss_//) )
+    _wanted services expl service compadd ${services%-*} && ret=0
+  ;;
+  databases)
+    if [[ $is_gnu = gnu ]]; then
+      databases=( ${=${${(f)"$(_call_program databases $words[1] --help \
+          2>/dev/null)"}[(r)Supported*,-1]}[2,-1]} )
+    else
+      databases=( passwd group hosts ipnodes services protocols ethers networks netmasks )
+    fi
+    _wanted databases expl database compadd -a databases && ret=0
+  ;;
+  keys)
+    keys=( ${(f)"$(_call_program keys $words[1] ${(kv)opt_args[(i)-s|--service]} $line[1] 2>/dev/null)"} )
+    case $line[1] in
+      *hosts) _wanted keys expl key compadd ${=keys#* } && ret=0 ;;
+      networks|rpc|protocols|services)
+        _wanted keys expl key compadd ${=keys%% *} && ret=0
+      ;;
+      aliases|passwd|shadow|group)
+        _wanted keys expl key compadd ${keys%%:*} && ret=0
+      ;;
+      *) _message -e keys key;;
+    esac
+  ;;
+esac
+
+return ret
Index: Completion/Debian/Command/_aptitude
===================================================================
RCS file: Completion/Debian/Command/_aptitude
diff -N Completion/Debian/Command/_aptitude
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Debian/Command/_aptitude	14 Jan 2004 16:51:24 -0000
@@ -0,0 +1,50 @@
+#compdef aptitude
+
+local curcontext="$curcontext" state line cmds ret=1
+
+_arguments -C \
+  '(- 1 *)'{-h,--help}'[display help information]' \
+  '(- 1 *)--version[display version information]' \
+  '(-s --simulate)'{-s,--simulate}'[print actions without performing them]' \
+  '(-d --download-only)'{-d,--download-only}"[just download packages - don't install]" \
+  '(-P --prompt)'{-P,--prompt}'[always display a prompt]' \
+  '(-y --assume-yes)'{-y,--assume-yes}'[assume yes answer to questions]' \
+  '(-F --display-format)'{-F,--display-format}'[specify output format for search command]:format' \
+  '(-U --sort)'{-U,--sort}'[specify sort order]:sort order:()' \
+  '(-w --width)'{-w,--width}'[specify output width]:width' \
+  '-f[aggressivley try to fix dependencies of broken packages]' \
+  '(--without-recommends)--with-recommends[install recommended packages when installing new packages]' \
+  '(--without-suggests)--with-suggests[install suggested packages when installing new packages]' \
+  '(--with-recommends)--without-recommends[ignore recommended packages when installing new packages]' \
+  '(--with-suggests)--without-suggests[ignore suggested packages when installing new packages]' \
+  '1: :->cmds' \
+  '*: :->args' && ret=0
+
+case $state in
+  cmds)
+    cmds=( ${${(M)${(f)"$(aptitude -h 2>/dev/null)"}:#* - *}/(#b) (*[^ ]) #- (*)/$match[1]:$match[2]:l})
+
+    _describe -t commands 'aptitude command' cmds && ret=0
+  ;;
+  args)
+    case $line[1] in
+      search)
+        _message -e patterns pattern
+      ;;
+      download)
+        _deb_packages avail
+      ;;
+      remove|purge|hold)
+        _deb_packages installed
+      ;;
+      install|markauto|unmarkauto)
+        _deb_packages uninstalled
+      ;;
+      *)
+        (( ret )) && _message 'no more arguments'
+      ;;
+    esac
+  ;;
+esac
+
+return ret
Index: Completion/Zsh/Command/_precommand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_precommand,v
retrieving revision 1.3
diff -u -r1.3 _precommand
--- Completion/Zsh/Command/_precommand	14 Nov 2003 11:56:56 -0000	1.3
+++ Completion/Zsh/Command/_precommand	14 Jan 2004 16:51:24 -0000
@@ -1,4 +1,4 @@
-#compdef - nohup env eval time rusage noglob nocorrect exec
+#compdef - nohup env eval time rusage noglob nocorrect exec catchsegv
 
 shift words
 (( CURRENT-- ))


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

* Re: PATCH: new completions
  2004-01-14 16:58 PATCH: new completions Oliver Kiddle
@ 2004-01-15  7:33 ` Bart Schaefer
  2004-01-15  9:41   ` Oliver Kiddle
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2004-01-15  7:33 UTC (permalink / raw)
  To: Zsh workers

On Jan 14,  5:58pm, Oliver Kiddle wrote:
}
} Just a couple of new completion functions.
} 
} Index: Completion/Zsh/Command/_precommand
} ===================================================================
} -#compdef - nohup env eval time rusage noglob nocorrect exec
} +#compdef - nohup env eval time rusage noglob nocorrect exec catchsegv

Does this really belong here?  "catchsegv" is an external command,
not a builtin; it's certainly not a precommand modifier.


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

* Re: PATCH: new completions
  2004-01-15  7:33 ` Bart Schaefer
@ 2004-01-15  9:41   ` Oliver Kiddle
  0 siblings, 0 replies; 11+ messages in thread
From: Oliver Kiddle @ 2004-01-15  9:41 UTC (permalink / raw)
  To: Zsh workers

Bart wrote:

> } Index: Completion/Zsh/Command/_precommand
> } ===================================================================
> } -#compdef - nohup env eval time rusage noglob nocorrect exec
> } +#compdef - nohup env eval time rusage noglob nocorrect exec catchsegv
> 
> Does this really belong here?  "catchsegv" is an external command,
> not a builtin; it's certainly not a precommand modifier.

As my excuse, I shall point out that that the same applies to rusage and
there have been other similar commands such as nice that were here in
the past (before getting their own function). And the name `_precommand'
doesn't necessarily imply the modifier part of 'precommand modifier'.

So if we add a copy of _precommand in Unix/Command what can it be
called? Or is it better to just keep this in one place?

Oliver


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

* Re: PATCH: New completions
  1999-06-18 13:04 ` Falk Hueffner
@ 1999-06-18 13:31   ` Tanaka Akira
  0 siblings, 0 replies; 11+ messages in thread
From: Tanaka Akira @ 1999-06-18 13:31 UTC (permalink / raw)
  To: zsh-workers

In article <st2bted64no.fsf@mirjam.informatik.uni-tuebingen.de>,
  Falk Hueffner <falk.hueffner@student.uni-tuebingen.de> writes:

> "hpux10.10" or similar.

Oops. Please ignore patches in 6712 and 6715.

--- Completion/User/_chown-	Fri Jun 18 20:55:51 1999
+++ Completion/User/_chown	Fri Jun 18 22:28:54 1999
@@ -1,10 +1,14 @@
 #compdef chown chgrp
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
-  if [[ $words[1] = chgrp ]] || compset -P '*.'; then
+  if [[ $words[1] = chgrp ]] || compset -P '*[:.]'; then
     _groups
   else
-    compgen -u -S '.' -q
+    if [[ $OSTYPE = (solaris*|hpux*) ]]; then
+      compgen -u -S ':' -q
+    else
+      compgen -u -S '.' -q
+    fi
   fi
 else
   _files

-- 
Tanaka Akira


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

* Re: PATCH: New completions
  1999-06-18 12:49 PATCH: New completions Kiddle, Oliver
  1999-06-18 13:04 ` Falk Hueffner
@ 1999-06-18 13:27 ` Tanaka Akira
  1 sibling, 0 replies; 11+ messages in thread
From: Tanaka Akira @ 1999-06-18 13:27 UTC (permalink / raw)
  To: zsh-workers

In article <4FBF540FF16FD1119D9600A0C94B2B51F29E91@napier.logica.co.uk>,
  "Kiddle, Oliver" <KiddleO@logica.com> writes:

> Does SunOS return solaris in $OSTYPE then - that's suprising.

Yes. It's bit tricky. But it works well because $OSTYPE is sunos4.* in
SunOS 4.x and solaris2.* in SunOS 5.x even in SunOS 5.7 --- Solaris 7.

# chown in SunOS 4.x supports "." only.

> HP/UX also
> uses a ':' so should be added to the pattern. I don't have access to it any
> more so can't tell you what it gives in $OSTYPE. I'd suggest using an if
> then else instead of the case statement as I've never seen a chown using
> anything other than . or :.

I don't know $OSTYPE in HP/UX too since I never use HP/UX.

--- Completion/User/_chown-	Fri Jun 18 20:55:51 1999
+++ Completion/User/_chown	Fri Jun 18 22:11:13 1999
@@ -1,10 +1,14 @@
 #compdef chown chgrp
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
-  if [[ $words[1] = chgrp ]] || compset -P '*.'; then
+  if [[ $words[1] = chgrp ]] || compset -P '*[:.]'; then
     _groups
   else
-    compgen -u -S '.' -q
+    if [[ $OSTYPE = solaris* ]]; then
+      compgen -u -S ':' -q
+    else
+      compgen -u -S '.' -q
+    fi
   fi
 else
   _files

-- 
Tanaka Akira


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

* Re: PATCH: New completions
  1999-06-18 12:49 PATCH: New completions Kiddle, Oliver
@ 1999-06-18 13:04 ` Falk Hueffner
  1999-06-18 13:31   ` Tanaka Akira
  1999-06-18 13:27 ` Tanaka Akira
  1 sibling, 1 reply; 11+ messages in thread
From: Falk Hueffner @ 1999-06-18 13:04 UTC (permalink / raw)
  To: zsh-workers

"Kiddle, Oliver" <KiddleO@logica.com> writes:

> HP/UX also uses a ':' so should be added to the pattern. I don't
> have access to it any more so can't tell you what it gives in
> $OSTYPE.

"hpux10.10" or similar.

	Falk


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

* Re: PATCH: New completions
@ 1999-06-18 12:49 Kiddle, Oliver
  1999-06-18 13:04 ` Falk Hueffner
  1999-06-18 13:27 ` Tanaka Akira
  0 siblings, 2 replies; 11+ messages in thread
From: Kiddle, Oliver @ 1999-06-18 12:49 UTC (permalink / raw)
  To: 'zsh-workers@sunsite.auc.dk'
  Cc: 'Tanaka Akira <akr@jaist.ac.jp>'

Tanaka Akira wrote:
> 
> This uses "." as a separator between owner and group for chown.
> But SunOS 5.x uses ":" instead of ".".

> +    case $OSTYPE in
> +      solaris*) compgen -u -S ':' -q;;

Does SunOS return solaris in $OSTYPE then - that's suprising. HP/UX also
uses a ':' so should be added to the pattern. I don't have access to it any
more so can't tell you what it gives in $OSTYPE. I'd suggest using an if
then else instead of the case statement as I've never seen a chown using
anything other than . or :.

> Hm. FreeBSD supports "." in addition to ":" even though chown(8)
> doesn't explain.

Linux does aswell.

Oliver Kiddle


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

* Re: PATCH: New completions
  1999-06-18  9:30 Kiddle, Oliver
@ 1999-06-18 12:06 ` Tanaka Akira
  0 siblings, 0 replies; 11+ messages in thread
From: Tanaka Akira @ 1999-06-18 12:06 UTC (permalink / raw)
  To: zsh-workers

In article <4FBF540FF16FD1119D9600A0C94B2B51F29E90@napier.logica.co.uk>,
  "Kiddle, Oliver" <KiddleO@logica.com> writes:

> + #compdef chown chgrp

This uses "." as a separator between owner and group for chown.
But SunOS 5.x uses ":" instead of ".".

--- Completion/User/_chown-	Fri Jun 18 20:55:51 1999
+++ Completion/User/_chown	Fri Jun 18 20:54:45 1999
@@ -1,10 +1,13 @@
 #compdef chown chgrp
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
-  if [[ $words[1] = chgrp ]] || compset -P '*.'; then
+  if [[ $words[1] = chgrp ]] || compset -P '*[:.]'; then
     _groups
   else
-    compgen -u -S '.' -q
+    case $OSTYPE in
+      solaris*) compgen -u -S ':' -q;;
+      *) compgen -u -S '.' -q;;
+    esac
   fi
 else
   _files

Hm. FreeBSD supports "." in addition to ":" even though chown(8)
doesn't explain.
-- 
Tanaka Akira


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

* Re: PATCH: New completions
@ 1999-06-18 10:36 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-06-18 10:36 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> This didn't apply after 6689, so here is a modified patch for that --
> with some other changes (I hope you find them acceptable). The list
> looks more like a select list and I avoided using `compgen -s'.

Oops... we should still be able to complete parameter names, I think
(unfortunately this may make the list much too long for the screen).

Bye
 Sven

diff -u oc/Base/_subscript Completion/Base/_subscript
--- oc/Base/_subscript	Fri Jun 18 12:02:08 1999
+++ Completion/Base/_subscript	Fri Jun 18 12:32:56 1999
@@ -8,7 +8,10 @@
   else
     compadd -S ']' - "${(@kP)${compstate[parameter]}}"
   fi
-elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
+  return
+fi
+
+if [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
    ind=( {1..${#${(P)${compstate[parameter]}}}} )
    list=()
    for i in "$ind[@]"; do
@@ -21,6 +24,6 @@
   else
     compadd -S ']' -y list - "$ind[@]"
   fi
-else
-  _compalso -math-
 fi
+
+_compalso -math-

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: New completions
@ 1999-06-18 10:01 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-06-18 10:01 UTC (permalink / raw)
  To: zsh-workers


Kiddle, Oliver wrote:

> The other patch (for _subscript) is a bit messy and can almost certainly be
> improved. Basically it completes the index in an array  by using -y to
> supply a list of each array element. I find it very useful for pulling
> single directories out of $manpath, $fpath etc.

This didn't apply after 6689, so here is a modified patch for that --
with some other changes (I hope you find them acceptable). The list
looks more like a select list and I avoided using `compgen -s'.

Hm, `compgen -s', maybe we should document it that this is almost
always unnecessary (after 6692). Or maybe we should even disallow the
`-s' option for `compgen'.

BUT: thank you for sharing your completion functions with us. I'd like 
to see more of this.

Bye
 Sven

--- oc/Base/_subscript	Thu Jun 17 12:04:14 1999
+++ Completion/Base/_subscript	Fri Jun 18 11:55:00 1999
@@ -1,10 +1,25 @@
 #compdef -subscript-
 
+local list ind
+
 if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
   if [[ "$RBUFFER" = \]* ]]; then
     compadd -S '' - "${(@kP)${compstate[parameter]}}"
   else
     compadd -S ']' - "${(@kP)${compstate[parameter]}}"
+  fi
+elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
+   ind=( {1..${#${(P)${compstate[parameter]}}}} )
+   list=()
+   for i in "$ind[@]"; do
+     [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
+         list=( "$list[@]" "${(r:4:: ::):)i} ${(P)${compstate[parameter]}[$i]}" )
+   done
+
+  if [[ "$RBUFFER" = \]* ]]; then
+    compadd -S '' -y list - "$ind[@]"
+  else
+    compadd -S ']' -y list - "$ind[@]"
   fi
 else
   _compalso -math-

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* PATCH: New completions
@ 1999-06-18  9:30 Kiddle, Oliver
  1999-06-18 12:06 ` Tanaka Akira
  0 siblings, 1 reply; 11+ messages in thread
From: Kiddle, Oliver @ 1999-06-18  9:30 UTC (permalink / raw)
  To: 'zsh-workers@sunsite.auc.dk'

First, I've written a new-style completion for chown/chgrp. I've also
patched _x_options to complete hostnames after -display with a ':0' suffix.

The other patch (for _subscript) is a bit messy and can almost certainly be
improved. Basically it completes the index in an array  by using -y to
supply a list of each array element. I find it very useful for pulling
single directories out of $manpath, $fpath etc.

Oliver Kiddle

diff -r -c Completion.old/Base/_subscript Completion/Base/_subscript
*** Completion.old/Base/_subscript	Tue Apr 13 07:37:36 1999
--- Completion/Base/_subscript	Fri Jun 18 09:54:46 1999
***************
*** 1,7 ****
--- 1,16 ----
  #compdef -subscript-
  
+ local list i j
+ 
  if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
    compgen -S ']' -k "( ${(kP)${compstate[parameter]}} )"
+ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
+    list=("$(for i in {1..${#${(P)${compstate[parameter]}}}}; do
+      typeset -L 5 j=$i
+      [ "${(P)${compstate[parameter]}[$i]}" ] && \
+ 	 echo "$j ${(P)${compstate[parameter]}[$i]}"
+    done)")
+    compgen -S ']' -y '$list' -s '{1..${#${(P)${compstate[parameter]}}}}'
  else
    _compalso -math-
  fi
diff -r -c Completion.old/User/_chown Completion/User/_chown
*** Completion.old/User/_chown	Fri Jun 18 09:58:59 1999
--- Completion/User/_chown	Fri Jun 18 09:55:12 1999
***************
*** 0 ****
--- 1,11 ----
+ #compdef chown chgrp
+ 
+ if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
+   if [[ $words[1] = chgrp ]] || compset -P '*.'; then
+     _groups
+   else
+     compgen -u -S '.' -q
+   fi
+ else
+   _files
+ fi
diff -r -c Completion.old/User/_groups Completion/User/_groups
*** Completion.old/User/_groups	Fri Jun 18 10:00:03 1999
--- Completion/User/_groups	Fri Jun 18 09:55:12 1999
***************
*** 0 ****
--- 1,6 ----
+ #compdef newgrp
+ 
+ : ${(A)groups:=${${(s: :)$(</etc/group)}%%:*}}
+ # : ${(A)groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use NIS
+ 
+ compadd $groups
diff -r -c Completion.old/User/_x_options Completion/User/_x_options
*** Completion.old/User/_x_options	Tue Apr 13 07:37:42 1999
--- Completion/User/_x_options	Fri Jun 18 10:15:49 1999
***************
*** 2,5 ****
  
  # A simple pattern completion, just as an example.
  
! compgen -J options -k '(-display -name -xrm)'
--- 2,9 ----
  
  # A simple pattern completion, just as an example.
  
! if [ "$words[CURRENT-1]" = "-display" ]; then
!   compgen -k hosts -S':0'
! else
!   compadd -J options - -display -name -xrm
! fi


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

end of thread, other threads:[~2004-01-15  9:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-14 16:58 PATCH: new completions Oliver Kiddle
2004-01-15  7:33 ` Bart Schaefer
2004-01-15  9:41   ` Oliver Kiddle
  -- strict thread matches above, loose matches on Subject: below --
1999-06-18 12:49 PATCH: New completions Kiddle, Oliver
1999-06-18 13:04 ` Falk Hueffner
1999-06-18 13:31   ` Tanaka Akira
1999-06-18 13:27 ` Tanaka Akira
1999-06-18 10:36 Sven Wischnowsky
1999-06-18 10:01 Sven Wischnowsky
1999-06-18  9:30 Kiddle, Oliver
1999-06-18 12:06 ` 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).