From 90f7a583e4bc4219fcceec60cf5e610b40a633a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20D=C3=A9moulins?= <clement@archivel.fr>
Date: Wed, 18 May 2011 22:16:02 +0200
Subject: [PATCH] Add a zsh completion script for the command rc.d.

---
 Makefile |    3 ++-
 _rc.d    |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletions(-)
 create mode 100644 _rc.d

diff --git a/Makefile b/Makefile
index 6923840..36668d3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 VER  := $(shell git describe)
-DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin
+DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin /usr/share/zsh/site-functions
 
 minilogd: minilogd.o
 
@@ -13,6 +13,7 @@ install: minilogd installdirs
 	install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime
 	install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs
 	install -m755 -t $(DESTDIR)/sbin minilogd rc.d
+	install -m644 -t $(DESTDIR)/usr/share/zsh/site-functions _rc.d
 
 clean:
 	rm -f minilogd minilogd.o
diff --git a/_rc.d b/_rc.d
new file mode 100644
index 0000000..b222bb6
--- /dev/null
+++ b/_rc.d
@@ -0,0 +1,36 @@
+#compdef rc.d
+
+_rc.d () {
+    local curcontext="$curcontext" state line
+    typeset -A opt_args
+
+    _arguments \
+        "1: :->action" \
+        "*: :->service"
+
+    case $state in
+        action)
+            _arguments "1:action:(list help start stop restart)"
+            ;;
+        service)
+            local action="$words[2]"
+            curcontext="${curcontext%:*:*}:rc.d-${action}:"
+
+            case $action in
+                list)
+                    _arguments "*: :"
+                    ;;
+                help)
+                    _arguments "*: :"
+                    ;;
+                *)
+                    _arguments "*: :_services"
+                    ;;
+            esac
+            ;;
+    esac
+}
+
+_rc.d "$@"
+
+# vim: filetype=zsh
-- 
1.7.5.1

