zsh-workers
 help / color / mirror / code / Atom feed
* Completion function patches
@ 2009-10-04 13:04 Edgar Merino
  2009-10-04 18:13 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Edgar Merino @ 2009-10-04 13:04 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Hello, I recently had to work with two utility functions for the 
completion system: _services and _init_d. I'm running archlinux and here 
services are under the /etc/rc.d directory, instead of the default 
directory that appears in those 2 scripts (/etc/init.d). Attached I 
provide you with pataches for both scripts, so that they work fine when 
running a system with an init framework similar to mine. Please let me 
know if I should do something else to contribute this code.


Edgar Merino

[-- Attachment #2: _init_d.patch --]
[-- Type: text/plain, Size: 472 bytes --]

--- _init_d	2009-10-04 07:54:44.000000000 -0500
+++ _init_d.new	2009-10-04 07:38:15.000000000 -0500
@@ -7,7 +7,7 @@
 # This should probably be system specific...
 
 script=$words[1]
-[[ $script = */* ]] || script=/etc/init.d/$script
+[[ $script = */* ]] || script=`[ -d /etc/init.d ] && echo /etc/init.d || echo /etc/rc.d`/$script
 
 # 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.

[-- Attachment #3: _services.patch --]
[-- Type: text/plain, Size: 491 bytes --]

--- _services	2009-10-04 08:00:36.000000000 -0500
+++ _services.new	2009-10-04 07:38:25.000000000 -0500
@@ -12,7 +12,8 @@
     'init:init service:compadd -a inits' \
     'xinetd:xinetd service:compadd -a xinetds' && ret=0
 else
-  _wanted services expl service compadd "$@" - /etc/init.d/*(-*:t) && ret=0
+  services_directory=`[ -d /etc/init.d ] && echo /etc/init.d || echo /etc/rc.d`;
+  _wanted services expl service compadd "$@" - $services_directory/*(-*:t) && ret=0
 fi
 
 return ret

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

* Re: Completion function patches
  2009-10-04 13:04 Completion function patches Edgar Merino
@ 2009-10-04 18:13 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2009-10-04 18:13 UTC (permalink / raw)
  To: zsh-workers

On Sun, 04 Oct 2009 08:04:14 -0500
Edgar Merino <donvodka@gmail.com> wrote:
> Hello, I recently had to work with two utility functions for the 
> completion system: _services and _init_d. I'm running archlinux and here 
> services are under the /etc/rc.d directory, instead of the default 
> directory that appears in those 2 scripts (/etc/init.d). Attached I 
> provide you with pataches for both scripts, so that they work fine when 
> running a system with an init framework similar to mine. Please let me 
> know if I should do something else to contribute this code.

Thanks, I'll commit the following.

Index: Completion/Unix/Command/_init_d
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_init_d,v
retrieving revision 1.8
diff -u -r1.8 _init_d
--- Completion/Unix/Command/_init_d	8 Oct 2007 08:40:14 -0000	1.8
+++ Completion/Unix/Command/_init_d	4 Oct 2009 18:10:02 -0000
@@ -7,7 +7,20 @@
 # This should probably be system specific...
 
 script=$words[1]
-[[ $script = */* ]] || script=/etc/init.d/$script
+if [[ $script != */* ]]; then
+  local -a scriptpath
+  local dir
+  # Known locations of init scripts
+  # C.f. Unix/Type/_services
+  scriptpath=(/etc/init.d /etc/rc.d /etc/rc.d/init.d)
+
+  for dir in $scriptpath; do
+    if [[ -f $dir/$script ]]; then
+      script=$dir/$script
+      break
+    fi
+  done
+fi
 
 # 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.
Index: Completion/Unix/Type/_services
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_services,v
retrieving revision 1.4
diff -u -r1.4 _services
--- Completion/Unix/Type/_services	8 Jun 2005 12:45:36 -0000	1.4
+++ Completion/Unix/Type/_services	4 Oct 2009 18:10:02 -0000
@@ -12,7 +12,19 @@
     'init:init service:compadd -a inits' \
     'xinetd:xinetd service:compadd -a xinetds' && ret=0
 else
-  _wanted services expl service compadd "$@" - /etc/init.d/*(-*:t) && ret=0
+  local -a scriptpath
+  local dir
+  # Known locations of init scripts
+  # C.f. Unix/Commands/_init_d
+  scriptpath=(/etc/init.d /etc/rc.d /etc/rc.d/init.d)
+
+  for dir in $scriptpath; do
+    if [[ -d $dir ]]; then
+      break
+    fi
+  done
+  _wanted services expl service compadd "$@" - $dir/*(-*:t) &&
+  ret=0
 fi
 
 return ret

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2009-10-04 18:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-04 13:04 Completion function patches Edgar Merino
2009-10-04 18:13 ` Peter Stephenson

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