zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: completion function for apachectl
@ 2001-03-08 10:15 Sven Wischnowsky
  2001-03-11 11:34 ` init.d completion Andrej Borsenkow
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2001-03-08 10:15 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Feb 26,  6:17pm, Andrej Borsenkow wrote:
> }
> } > +_sub_commands start stop
> } 
> } Well, Linux strikes again. You can be sure only in the above; restart and
> } status are not universally supported.
> 
> One could probably pull a stunt like this:
> 
> _sub_commands $(sed -ne '/case/,/esac/{;s/^ *\([a-z|)]*\).*/\1/g;s/[|)]/ /gp;}' $words[1])
> 
> Runs a slight risk of finding case-labels that aren't actually part of the
> argument parsing -- on a RedHat 6.2 machine it finds y, n, and c in one of
> the scripts -- but for the most part it's pretty accurate.
> 
> Tuning the regex and adapting to older seds left as an exercise.

Using external programs?  To quote Peter: pah!

The thing below works for me.  To make Andrej happy it searches for a
couple of known words instead of using every line that looks like...


Bye
 Sven

Index: Completion/User/_init_d
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/User/_init_d,v
retrieving revision 1.1
diff -u -r1.1 _init_d
--- Completion/User/_init_d	2001/02/26 15:05:37	1.1
+++ Completion/User/_init_d	2001/03/08 10:15:00
@@ -1,5 +1,22 @@
 #compdef -P */(init|rc[0-9]#).d/*
 
+local magic cmds what
+
 # This should probably be system specific...
+
+# If the file starts with `#!' we hope that this is a shell script
+# and get lines looking like <space>foo|bar) with the words in $what.
+
+what='(st(art|op|atus)|re(start|load)|debug_(up|down)|dump(|_stats)|add|delete|clean|list)'
+
+read -u0k 2 magic < $words[1] && [[ $magic = '#!' ]] &&
+    cmds=( ${${(j:|:s:|:)${(M)${(f)"$(< $words[1])"}:#[[:blank:]]#(\'|)${~what}(|${~what})#(\'|)\)}}//[^a-z_]} )
+
+# This would be the pattern to use every line of the form <space>foo).
+# Some people say this might match too many lines...
+#
+#    cmds=( ${${(j:|:s:|:)${(M)${(f)"$(< $words[1])"}:#[[:blank:]]#(\'|)[a-z_|]##(\'|)\)}}//[^a-z_]} )
+
+(( $#cmds )) || cmds=(start stop)
 
-_sub_commands start stop
+_sub_commands $cmds

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


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

* init.d completion
  2001-03-08 10:15 PATCH: Re: completion function for apachectl Sven Wischnowsky
@ 2001-03-11 11:34 ` Andrej Borsenkow
  2001-03-11 15:00   ` Trond Eivind Glomsrød
  2001-03-11 17:38   ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Andrej Borsenkow @ 2001-03-11 11:34 UTC (permalink / raw)
  To: zsh-workers

Most (many) of scripts in our /etc/init.d are not executable, so I have to use
'sh foo' instead of plain 'foo'. Not sure how to handle it; putting special
case in sh completion?

-andrej


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

* Re: init.d completion
  2001-03-11 11:34 ` init.d completion Andrej Borsenkow
@ 2001-03-11 15:00   ` Trond Eivind Glomsrød
  2001-03-11 17:38   ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Trond Eivind Glomsrød @ 2001-03-11 15:00 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: zsh-workers

"Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru> writes:

> Most (many) of scripts in our /etc/init.d are not executable,

All of them are here (Red Hat Linux - Wolverine), and I think they should be...
Anyway, running with "service foo start" is easier than completing a
specific directory... the first argument should be completed with
/etc/init.d/* (minus functions), the second would be possible
arguments of this script. This can be found in the usage string:

"Usage: $0 {start|stop|status|restart|condrestart|reload}"

Just grep what's inside the curly braces, and split it on "|".

-- 
Trond Eivind Glomsrød
Red Hat, Inc.


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

* Re: init.d completion
  2001-03-11 11:34 ` init.d completion Andrej Borsenkow
  2001-03-11 15:00   ` Trond Eivind Glomsrød
@ 2001-03-11 17:38   ` Bart Schaefer
  2001-03-11 18:17     ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-03-11 17:38 UTC (permalink / raw)
  To: Andrej Borsenkow, zsh-workers

On Mar 11,  2:34pm, Andrej Borsenkow wrote:
} Subject: init.d completion
}
} Most (many) of scripts in our /etc/init.d are not executable, so I have to
} use 'sh foo' instead of plain 'foo'. Not sure how to handle it; putting
} special case in sh completion?

_sh is pretty braindead at the moment.  Unless you're using "sh -c ..."
it only uses _default completion.  Here's a fairly simple potential fix:


Index: Completion/User/_sh
===================================================================
diff -c -r1.1.1.1 _sh
--- Completion/User/_sh	1999/07/20 08:11:00	1.1.1.1
+++ Completion/User/_sh	2001/03/11 17:28:10
@@ -4,5 +4,6 @@
   compset -q
   _normal
 else
-  _default
+  compset -n ${words[(b:2:i)[^-]*]}
+  _normal || _default
 fi


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: init.d completion
  2001-03-11 17:38   ` Bart Schaefer
@ 2001-03-11 18:17     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2001-03-11 18:17 UTC (permalink / raw)
  To: Andrej Borsenkow, zsh-workers

On Mar 11,  5:38pm, Bart Schaefer wrote:
} Subject: Re: init.d completion
}
} On Mar 11,  2:34pm, Andrej Borsenkow wrote:
} } Subject: init.d completion
} }
} } Most (many) of scripts in our /etc/init.d are not executable, so I have to
} } use 'sh foo' instead of plain 'foo'. Not sure how to handle it; putting
} } special case in sh completion?
} 
} _sh is pretty braindead at the moment.  Unless you're using "sh -c ..."
} it only uses _default completion.  Here's a fairly simple potential fix:

Sorry, that doesn't quite cut it.  Better:


Index: Completion/User/_sh
===================================================================
diff -c -r1.1.1.1 _sh
--- Completion/User/_sh	1999/07/20 08:11:00	1.1.1.1
+++ Completion/User/_sh	2001/03/11 18:16:38
@@ -4,5 +4,10 @@
   compset -q
   _normal
 else
+  local n=${words[(b:2:i)[^-]*]}
+  if (( n <= CURRENT )); then
+    compset -n $n
+    _normal && return 0
+  fi
   _default
 fi

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-03-11 18:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 10:15 PATCH: Re: completion function for apachectl Sven Wischnowsky
2001-03-11 11:34 ` init.d completion Andrej Borsenkow
2001-03-11 15:00   ` Trond Eivind Glomsrød
2001-03-11 17:38   ` Bart Schaefer
2001-03-11 18:17     ` Bart Schaefer

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).