* 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread
* Re: PATCH: Re: completion function for apachectl
2001-02-26 16:07 ` Bart Schaefer
@ 2001-02-26 18:41 ` Andrej Borsenkow
0 siblings, 0 replies; 10+ messages in thread
From: Andrej Borsenkow @ 2001-02-26 18:41 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
On Mon, 26 Feb 2001, 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.
>
>
I prefer explicit search for (start|stop|restart|status|reload). It is
what is used on Linux (just checked) and we can always add more labels
if needed. Searching for every label will find too much.
One small problem is binary programs (at least our system sometimes did
that). So, '2> /dev/null' is needed and at least (start|stop) should be
fallback.
-andrej
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: PATCH: Re: completion function for apachectl
2001-02-26 15:17 ` Andrej Borsenkow
@ 2001-02-26 16:07 ` Bart Schaefer
2001-02-26 18:41 ` Andrej Borsenkow
0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2001-02-26 16:07 UTC (permalink / raw)
To: zsh-workers
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.
--
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] 10+ messages in thread
* RE: PATCH: Re: completion function for apachectl
@ 2001-02-26 15:34 Sven Wischnowsky
0 siblings, 0 replies; 10+ messages in thread
From: Sven Wischnowsky @ 2001-02-26 15:34 UTC (permalink / raw)
To: zsh-workers
Andrej Borsenkow wrote:
> ...
>
> Well, Linux strikes again. You can be sure only in the above; restart and
> status are not universally supported.
Question is if we can dare to grep the file for "^[[:blank:]]*'?[a-z_|]+'?\)"
or some such and then use those strings (after cleanup/splitting, obviously).
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: PATCH: Re: completion function for apachectl
2001-02-26 15:04 Sven Wischnowsky
@ 2001-02-26 15:17 ` Andrej Borsenkow
2001-02-26 16:07 ` Bart Schaefer
0 siblings, 1 reply; 10+ messages in thread
From: Andrej Borsenkow @ 2001-02-26 15:17 UTC (permalink / raw)
To: zsh-workers
> Index: Completion/User/_init_d
> ===================================================================
> RCS file: _init_d
> diff -N _init_d
> --- /dev/null Mon Dec 11 17:26:27 2000
> +++ _init_d Mon Feb 26 07:00:21 2001
> @@ -0,0 +1,5 @@
> +#compdef -P */(init|rc[0-9]#).d/*
> +
> +# This should probably be system specific...
> +
> +_sub_commands start stop
>
Well, Linux strikes again. You can be sure only in the above; restart and
status are not universally supported.
-andrej
P.S. Now, when I finally have Mandrake @home I welcome any Linux addition
actualy :-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* PATCH: Re: completion function for apachectl
@ 2001-02-26 15:04 Sven Wischnowsky
2001-02-26 15:17 ` Andrej Borsenkow
0 siblings, 1 reply; 10+ messages in thread
From: Sven Wischnowsky @ 2001-02-26 15:04 UTC (permalink / raw)
To: zsh-workers
Fletch wrote:
> ...
>
> [... Brutal savaging of my version choped :) ]
;-) sorry...
> ...
>
> I've been frustrated that TAB doesn't Do What I Mean for stuff
> in /etc/rc.d/init.d several times. You almost could generate it on
> the fly with a for over /etc/rc.d/init.d/*, maybe with a style for
> things that take strange arguments other than start or stop.
So here are some small functions... I didn't use a style yet, maybe
we'll be able to add some system specific magic so that users don't
have to be bothered...
That change in _normal makes it use ${PWD}/$words[1] when completing
arguments for something that is given as a relative path (`./foo <TAB>').
Bye
Sven
Index: Completion/Base/_sub_commands
===================================================================
RCS file: _sub_commands
diff -N _sub_commands
--- /dev/null Mon Dec 11 17:26:27 2000
+++ _sub_commands Mon Feb 26 07:00:21 2001
@@ -0,0 +1,9 @@
+#autoload
+
+local expl
+
+if [[ CURRENT -eq 2 ]]; then
+ _wanted commands expl command compadd "$@"
+else
+ _message 'no more arguments'
+fi
Index: Completion/Core/_normal
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_normal,v
retrieving revision 1.5
diff -u -r1.5 _normal
--- Completion/Core/_normal 2001/01/15 09:11:32 1.5
+++ Completion/Core/_normal 2001/02/26 15:00:21
@@ -30,6 +30,10 @@
eval cmd1\=$command
cmd2="$command[2,-1]"
curcontext="${curcontext%:*:*}:${cmd2}:"
+ elif [[ "$command" = ..#/* ]]; then
+ cmd1="${PWD}/$command"
+ cmd2="${command:t}"
+ curcontext="${curcontext%:*:*}:${cmd2}:"
elif [[ "$command" = */* ]]; then
cmd1="$command"
cmd2="${command:t}"
Index: Completion/User/_apachectl
===================================================================
RCS file: _apachectl
diff -N _apachectl
--- /dev/null Mon Dec 11 17:26:27 2000
+++ _apachectl Mon Feb 26 07:00:21 2001
@@ -0,0 +1,3 @@
+#compdef apachectl
+
+_sub_commands start startssl stop restart fullstatus status graceful configtest help
Index: Completion/User/_init_d
===================================================================
RCS file: _init_d
diff -N _init_d
--- /dev/null Mon Dec 11 17:26:27 2000
+++ _init_d Mon Feb 26 07:00:21 2001
@@ -0,0 +1,5 @@
+#compdef -P */(init|rc[0-9]#).d/*
+
+# This should probably be system specific...
+
+_sub_commands start stop
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2001-03-11 18:18 UTC | newest]
Thread overview: 10+ 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
-- strict thread matches above, loose matches on Subject: below --
2001-02-26 15:34 PATCH: Re: completion function for apachectl Sven Wischnowsky
2001-02-26 15:04 Sven Wischnowsky
2001-02-26 15:17 ` Andrej Borsenkow
2001-02-26 16:07 ` Bart Schaefer
2001-02-26 18:41 ` Andrej Borsenkow
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).