Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: completions for pkgin and avahi



These are a couple of completions that I tried submitting to their
respective upstreams some time ago but which got ignored. Specifically,
pkgin and avahi.

Oliver

diff --git a/Completion/BSD/Command/_pkgin b/Completion/BSD/Command/_pkgin
new file mode 100644
index 000000000..5cb12baea
--- /dev/null
+++ b/Completion/BSD/Command/_pkgin
@@ -0,0 +1,79 @@
+#compdef pkgin
+
+local curcontext="$curcontext" pkgin=$words[1] cmd ret=1
+local -a state state_descr line expl cmds short pkgs
+local -A opt_args
+
+_arguments -s -S -C \
+  '-c+[enable chrooting pkgin in the given repository]:chroot path:_directories' \
+  '-d[download only]' \
+  '-f[force database update]' \
+  '-F[force package reinstall]' \
+  '(- 1 *)-h[display usage information]' \
+  '-l+[only include the packages with the specified status flags]:limit chars:((
+    \=\:installed\ version\ is\ current
+    \<\:installed\ version\ is\ older
+    \>\:installed\ version\ is\ newer
+  ))' \
+  '(-y)-n[assume "no" as default answer and print results of actions to be taken line per line]' \
+  '-p[display results in a parsable format]' \
+  '-P[display packages versions instead of globs (sd, sfd, srd)]' \
+  '-t+[log package browsing (dependencies and impact) to specified log file]:log file:_files' \
+  '(- 1 *)-v[display version information]' \
+  '-V[be verbose when (un)installing]' \
+  '(-n)-y[assume "yes" as default answer, except for autoremove]' \
+  '1:command:->subcommands' \
+  '*:: :->restargs' && ret=0
+
+if [[ -n $state ]]; then
+  cmds=( ${${${(f)"$(_call_program commands $pkgin -h 2>&1)"}[3,-1]/ -  (#b)(?)/:$match:l}%.} )
+  short=( ${${cmds#*\(}/ #\)/} )
+  cmds=( ${cmds// #\(*\)/} )
+  if [[ $state = subcommands && ! -prefix - ]]; then
+    _describe -t commands "command" short -- cmds -M 'r:|-=* r:|=*' && ret=0
+    return ret
+  fi
+
+  cmd=${short[(I)${words[1]}:*]}
+  if (( cmd )); then
+    cmd=${cmds[cmd]%%:*}
+  else
+    cmd=$words[1]
+  fi
+  curcontext="${curcontext%:*}-$cmd"
+  case $cmd in
+    avail|autoremove|clean|export|(full-|)upgrade|show(|-no)-keep|update)
+      _nothing
+    ;;
+    import)
+      _wanted files expl file _files && ret=0
+    ;;
+    install|pkg-(content|descr|build-defs)|provides|requires|show(|-full|-rev)-deps|show-pkg-category)
+      _wanted packages expl package compadd - \
+	  ${${(f)"$(_call_program packages $pkgin avail)"}%%-[^- ]# *} && ret=0
+    ;;
+    keep)
+      _wanted packages expl package compadd - \
+	  ${${(f)"$(_call_program packages $pkgin show-no-keep)"}%%-[^- ]# *} && ret=0
+    ;;
+    remove)
+      _wanted packages expl package compadd - \
+	  ${${(f)"$(_call_program packages $pkgin list)"}%%-[^- ]# *} && ret=0
+    ;;
+    search)
+      _message -e patterns pattern
+    ;;
+    show-category)
+      _wanted -x categories expl category compadd - /usr/pkgsrc/*~*/CVS(N/:t) && ret=0
+    ;;
+    unkeep)
+      _wanted packages expl package compadd - \
+	  ${${(f)"$(_call_program packages $pkgin show-keep)"}%%-[^- ]# *} && ret=0
+    ;;
+    *)
+      _default && ret=0
+    ;;
+  esac
+fi
+
+return ret
diff --git a/Completion/Unix/Command/_avahi b/Completion/Unix/Command/_avahi
new file mode 100644
index 000000000..562ec3647
--- /dev/null
+++ b/Completion/Unix/Command/_avahi
@@ -0,0 +1,52 @@
+#compdef avahi-browse avahi-browse-domains avahi-resolve avahi-resolve-address avahi-resolve-host-name
+
+local curcontext="$curcontext" pri ret=1
+local -A opt_args
+local -a state line args serv desc disp
+
+args=(
+  '(- 1)'{-h,--help}'[display usage information]'
+  '(- 1)'{-V,--version}'[display version information]'
+  '(-v --verbose)'{-v,--verbose}'[enable verbose mode]'
+)
+
+case $service in
+  *-browse*)
+    serv=( ${(f)"$(_call_program service-types avahi-browse -bk)"} )
+    desc=( ${(f)"$(_call_program service-types-description avahi-browse -b)"} )
+    (( $#desc )) && print -v disp -f '%s:%s' ${serv:^desc}
+
+    _arguments -s -S -C $args \
+      '(-D --browse-domains -a --all -b --dump-db)'{-D,--browse-domains}'[browse for browsing domains instead of services]' \
+      '(-D --browse-domains -a --all -b --dump-db)'{-a,--all}'[show all services, regardless of the type]' \
+      '(-d --domain)'{-d+,--domain=}'[specify domain to browse in]:domain' \
+      '(-t --terminate)'{-t,--terminate}'[terminate after dumping a more or less complete list]' \
+      '(-c --cache)'{-c,--cache}'[terminate after dumping all entries from the cache]' \
+      '(-l --ignore-local)'{-l,--ignore-local}'[ignore local services]' \
+      '(-r --resolve)'{-r,--resolve}'[resolve services found]' \
+      '(-f --no-fail)'{-f,--no-fail}"[don't fail if the daemon is not available]" \
+      '(-p --parsable)'{-p,--parsable}'[output in parsable format]' \
+      '(-k --no-db-lookup)'{-k,--no-db-lookup}"[don't lookup service types]" \
+      '(-D --browse-domains -a --all -b --dump-db)'{-b,--dump-db}'[dump service type database]' \
+      '1: :->service-types' && ret=0
+
+    [[ -n $state ]] && _describe -t services "service type" disp && ret=0
+  ;;
+  *-resolve*)
+    if (( ${words[(I)(-n|--name)]} )) || [[ $service = *-host-name ]]; then
+       args=( '*:host:_hosts' )
+       pri=1
+    fi
+    if (( ${words[(I)(-a|--address)]} )) || [[ $service = *-address && -n $pri ]]; then
+       args=( '*: :_guard "^-*" address' )
+    fi
+
+    _arguments -s -S $args \
+      '(-a --address -n --name -h --help -V --version)'{-a,--address}'[resolve address]' \
+      '(-a --address -n --name -h --help -V --version)'{-n,--name}'[resolve host name]' \
+      '(-4)-6[lookup IPv6 address]' \
+      '(-6)-4[lookup IPv4 address]' && ret=0
+  ;;
+esac
+
+return ret



Messages sorted by: Reverse Date, Date, Thread, Author