Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Completion: Improve _init_d command matching
- X-seq: zsh-workers 43713
- From: dana <dana@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Completion: Improve _init_d command matching
- Date: Thu, 18 Oct 2018 16:22:22 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=J7ktCyy9cCpKD2IX2kk9dw5uHqbkoG3eZNP+AHULDZc=; b=gVK1oPiAkmUzWBHThN4fNVNIF30G/KZUyYniQ7y8pKyGIgDG/7xWWz/OAOtXHvIVeE v9EtqUmxj0idiUcko5lnQZoGfywb0heetocnCOI3RMG/+9lgyQcVIpERjzcIm0QdSLMY u1hNeliSzKWlKxGPHtIrPedOaJ0m5rIga1AcfH6KHdLLwzf9yrwnSgDBG12+EclWMyNp hlAhtYDLp+k9MVYTFQdpeG8XwyT09hOZ/n7o+EVIYv8Ic8ZzSk98U6bRAlOdntNZz94P sf3JHH3spfTP+foW255tcHvf/k4406SzBh/PM4cr+DzPnXh8g+jhY9mQgsWguu4zONRP TiRw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Someone on IRC complained that they weren't getting all of the expected commands
when tab-completing `service apache2`. That's because _init_d won't match any
case clause containing a pattern that wasn't explicitly enumerated, and the
apache2 script had a bunch of those.
I updated the script to enumerate several more patterns that i found in the init
scripts on my Ubuntu machine and to make it match quoted patterns better. (I've
never seen a quoted pattern in any of these scripts, but someone once upon a
time apparently thought it was a good idea, so why not.) I also broke up some of
the code into (IMO) more readable chunks, so that hopefully the next person who
has to update this doesn't need to spend as much time on it as i did.
dana
diff --git a/Completion/Unix/Command/_init_d b/Completion/Unix/Command/_init_d
index 03af2dc9b..cdc373297 100644
--- a/Completion/Unix/Command/_init_d
+++ b/Completion/Unix/Command/_init_d
@@ -80,15 +80,29 @@ else
(( $+functions[_init_d_get_cmds] )) ||
_init_d_get_cmds() {
local what magic cmds
+ local -a tmp
- # 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.
+ [[ -x $script ]] || return 1
- what='(st(art|op|atus)|(force-|)re(start|load)|debug_(up|down)|dump(|_stats)|add|delete|clean|list)'
+ # 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. Note
+ # that we'll fail to match if any of the alternate patterns in the case
+ # clause are not enumerated (e.g., `start|stop|custom)` won't match)
+ tmp=(
+ status add delete clean list
+ load save show check {config,}test
+ standalone master graceful
+ debug debug{_,-}{up,down} dump{,{_,-}stats}
+ {force-,graceful-,try-,}{start,stop,restart,reload}
+ {start,stop}-htcacheclean
+ )
+ what="((['\"]|)(${(j<|>)tmp})(['\"]|))"
- [[ -x $script ]] || return 1
- read -u0 -k2 magic < $script && [[ $magic = '#!' ]] &&
- cmds=( ${${(j:|:s:|:)${(M)${(f)"$(< $script)"}:#[[:blank:]]#(\'|)${~what}([[:blank:]]#\|[[:blank:]]#${~what})#(\'|)\)}}//[^-a-z_]} )
+ read -u0 -k2 magic < $script && [[ $magic = '#!' ]] && {
+ cmds=( ${(f)"$(< $script)"} )
+ cmds=( ${(M)cmds:#[[:blank:]]#${~what}([[:blank:]]#\|[[:blank:]]#${~what})#[[:blank:]]#\)} )
+ cmds=( ${${(j:|:s:|:)cmds}//[^-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...
Messages sorted by:
Reverse Date,
Date,
Thread,
Author