Add mic zsh tab completion support
authorSun Lihong <lihongx.sun@intel.com>
Thu, 12 Sep 2013 13:36:09 +0000 (21:36 +0800)
committerGerrit Code Review <gerrit2@otctools.jf.intel.com>
Wed, 25 Sep 2013 04:09:33 +0000 (21:09 -0700)
Fixes: #1187

Change-Id: I6a668990556431c5df8304a830a12943cef975a0

debian/rules
etc/_mic [new file with mode: 0644]
packaging/mic.spec

index c1ff2ff..e142fa8 100755 (executable)
@@ -31,9 +31,10 @@ install: build
        dh_installdirs
 
        # Installing package
-       mkdir -p $(CURDIR)/debian/mic $(CURDIR)/debian/mic/usr/bin $(CURDIR)/debian/mic/usr/share/man/man1 $(CURDIR)/debian/mic/etc/bash_completion.d
+       mkdir -p $(CURDIR)/debian/mic $(CURDIR)/debian/mic/usr/bin $(CURDIR)/debian/mic/usr/share/man/man1 $(CURDIR)/debian/mic/etc/bash_completion.d $(CURDIR)/debian/mic/etc/zsh_completion.d
        install -m644 doc/mic.1 $(CURDIR)/debian/mic/usr/share/man/man1
        install -m755 etc/mic.bash $(CURDIR)/debian/mic/etc/bash_completion.d/mic.sh
+       install -m755 etc/_mic $(CURDIR)/debian/mic/etc/zsh_completion.d/_mic
        python setup.py install --root=$(CURDIR)/debian/mic
 
 binary-indep: build install
diff --git a/etc/_mic b/etc/_mic
new file mode 100644 (file)
index 0000000..65e3433
--- /dev/null
+++ b/etc/_mic
@@ -0,0 +1,187 @@
+#compdef mic
+#
+# Copyright (c) 2013 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+_mic() {
+  typeset -A opt_args
+  local context state line curcontext="$curcontext"
+
+  local ret=1
+
+  _arguments -C \
+    {-h,--help}'[show this help message and exit]' \
+    "--version[show program\'s version number and exit]" \
+    {-d,--debug}'[print debug message]' \
+    {-v,--verbose}'[verbose information]' \
+    '1: :_mic_cmds' \
+    '*::arg:->args' \
+  && ret=0
+
+
+  case "$state" in
+    (args)
+      curcontext="${curcontext%:*:*}:mic-cmd-$words[1]:"
+      case $words[1] in
+        (chroot|ch)
+          _arguments \
+            {-h,--help}'[show this help message and exit]' \
+            {-s,--saveto=}'[Save the unpacked image to specified dir]: :_files -/' \
+            '1: :_files -/' \
+              && ret=0
+        ;;
+        (convert|cv)
+          _arguments \
+            {-h,--help}'[show this help message and exit]' \
+            {-S,--shell}'[Launch shell before packaging the converted image]' \
+              && ret=0
+        ;;
+        (create|cr)
+          _arguments -C \
+            {-h,--help}'[show this help message and exit]' \
+            '--logfile=[Path of logfile]:path' \
+            '-c[Specify config file for mic]:file' \
+            '-k[Cache directory to store the downloaded]: :_files -/' \
+            '-o[Output directory]: :_files -/' \
+            '-A[Specify repo architecture]:parameter' \
+            '--release=[Generate a release of RID with all necessary files, when @BUILD_ID@ is contained in kickstart file, it will be replaced by RID]:parameter' \
+            '--record-pkgs=[Record the info of installed packages, multiple values can be specified which joined by \",\", valid values: \"name\", \"content\", \"license\", \"vcs\"]: :_mic_create_filters -s ,' \
+            '--pkgmgr=[Specify backend package manager]:parameter' \
+            '--local-pkgs-path=[Path for local pkgs(rpms) to be installed]:path' \
+            '--runtime=[Specify  runtime mode, avaiable: bootstrap, native]: :(bootstrap native)' \
+            '--pack-to=[Pack the images together into the specified achive, extension supported: .zip, .tar, .tar.gz, .tar.bz2, etc. by default, .tar will be used]:parameter' \
+            '--copy-kernel[Copy kernel files from image /boot directory to the image output directory.]' \
+            '--install-pkgs=[Specify what type of packages to be installed, valid: source, debuginfo, debugsource]: :(source debuginfo debugsource)' \
+            '--check-pkgs=[Check if given packages would be installed, packages should be separated by comma]' \
+            '--tmpfs[Setup tmpdir as tmpfs to accelerate, experimental feature, use it if you have more than 4G memory]' \
+            '1: :_mic_create_entities' \
+            '*::create-arg:->create-args' \
+              && ret=0
+          case "$state" in
+            (create-args)
+              local -a common_ops
+              common_ops=(
+                '1:: :(`ls`)' \
+                {-h,--help}'[show this help message and exit]' \
+                '--logfile=[Path of logfile]:path' \
+                '-c[Specify config file for mic]:file' \
+                '-k[Cache directory to store the downloaded]: :_files -/' \
+                '-o[Output directory]: :_files -/' \
+                '-A[Specify repo architecture]:parameter' \
+                '--release=[Generate a release of RID with all necessary files, when @BUILD_ID@ is contained in kickstart file, it will be replaced by RID]:parameter' \
+                '--record-pkgs=[Record the info of installed packages, multiple values can be specified which joined by \",\", valid values: \"name\", \"content\", \"license\", \"vcs\"]: :_mic_create_filters -s ,' \
+                '--pkgmgr=[Specify backend package manager]:parameter' \
+                '--local-pkgs-path=[Path for local pkgs(rpms) to be installed]:path' \
+                '--runtime=[Specify  runtime mode, avaiable: bootstrap, native]: :(bootstrap native)' \
+                '--pack-to=[Pack the images together into the specified achive, extension supported: .zip, .tar, .tar.gz, .tar.bz2, etc. by default, .tar will be used]:parameter' \
+                '--copy-kernel[Copy kernel files from image /boot directory to the image output directory.]' \
+                '--install-pkgs=[Specify what type of packages to be installed, valid: source, debuginfo, debugsource]: :(source debuginfo debugsource)' \
+                '--check-pkgs=[Check if given packages would be installed, packages should be separated by comma]' \
+                '--tmpfs[Setup tmpdir as tmpfs to accelerate, experimental feature, use it if you have more than 4G memory]' \
+              )
+              case $words[1] in
+                (auto)
+                  _arguments \
+                    $common_ops \
+                      && ret=0
+                  ;;
+                (fs)
+                  _arguments \
+                    $common_ops \
+                    '--include-src[Generate a image with source rpms included]' \
+                    && ret=0
+                  ;;
+                (livecd)
+                  _arguments \
+                    $common_ops \
+                      && ret=0
+                  ;;
+                (liveusb)
+                  _arguments \
+                    $common_ops \
+                      && ret=0
+                  ;;
+                (loop)
+                  _arguments \
+                    $common_ops \
+                    '--shrink[Whether to shrink loop images to minimal size]' \
+                    "--compress-image=[Compress all loop images with \'gz\' or \'bz2\']: :(gz bz2)" \
+                    "--compress-disk-image=[Same with --compress-image]: :(gz bz2)" \
+                      && ret=0
+                  ;;
+                (raw)
+                  _arguments \
+                    $common_ops \
+                    "--fstab-entry=[Set fstab entry, \'name\' means using device names, \'uuid\' means using filesystem uuid]: :(name uuid)" \
+                    '--generate-bmap[also generate the block map file]' \
+                    '--compress-image=[Compress all raw images before package]: :(gz bz2)' \
+                    '--compress-disk-image=[Same with --compress-image]: :(gz bz2)' \
+                    && ret=0
+                  ;;
+                (help)
+                  _arguments -C \
+                    '1: :_mic_create_entities' \
+                    && ret=0
+                  ;;
+              esac
+              ;;
+          esac
+         ;;
+         (help)
+           _arguments -C \
+             '1: :_mic_cmds' \
+             && ret=0
+        ;;
+      esac
+    ;;
+  esac
+
+  return ret
+}
+
+(( $+functions[_mic_cmds] )) ||
+_mic_cmds() {
+  local commands; commands=(
+    'chroot:chroot into an image'
+    'convert:convert image format'
+    'create:create an image'
+    'help:give detailed help on a specific sub-command'
+  )
+  _describe -t commands 'command' commands "$@"
+}
+
+(( $+functions[_mic_create_entities] )) ||
+_mic_create_entities() {
+  local entities; entities=(
+    'auto:auto detect image type from magic header'
+    'fs:create fs image'
+    'help:give detailed help on a specific sub-command'
+    'livecd:create livecd image'
+    'liveusb:create liveusb image'
+    'loop:create loop image'
+    'raw:create raw image'
+  )
+  _describe -t entities 'entity' entities "$@"
+}
+
+(( $+functions[_mic_create_filters] )) ||
+_mic_create_filters() {
+  local filters; filters=(name content license vcs)
+  _values $@ 'filter' "${filters[@]}"
+}
+
+_mic "$@"
+
+# vim: ft=zsh sw=2 ts=2 et
index f7f6e70..f756262 100644 (file)
@@ -108,6 +108,10 @@ install -m644 doc/mic.1 %{buildroot}/%{_prefix}/share/man/man1
 install -d -m0755 %{buildroot}/%{_sysconfdir}/bash_completion.d/
 install -Dp -m0755 etc/%{name}.bash %{buildroot}/%{_sysconfdir}/bash_completion.d/%{name}.sh
 
+# install zsh completion
+install -d -m0755 %{buildroot}/%{_sysconfdir}/zsh_completion.d/
+install -Dp -m0755 etc/_%{name} %{buildroot}/%{_sysconfdir}/zsh_completion.d/_%{name}
+
 %files
 %defattr(-,root,root,-)
 %doc doc/*
@@ -121,5 +125,5 @@ install -Dp -m0755 etc/%{name}.bash %{buildroot}/%{_sysconfdir}/bash_completion.
 %dir %{_prefix}/lib/%{name}
 %{_prefix}/lib/%{name}/*
 %{_bindir}/*
-%config %{_sysconfdir}/bash_completion.d/*
-
+%{_sysconfdir}/bash_completion.d
+%{_sysconfdir}/zsh_completion.d