about summary refs log tree commit diff
path: root/Completion/Debian
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-08 13:11:06 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-08 13:11:06 +0000
commitab54bf2baa7c319954e6c58f9cce9a498b2205ac (patch)
tree2d033962ff845715a216e859748299a1a6683b9d /Completion/Debian
parent8a35fcd4ba96c89cee950e173e6820eaf0378d5b (diff)
downloadzsh-ab54bf2baa7c319954e6c58f9cce9a498b2205ac.tar.gz
zsh-ab54bf2baa7c319954e6c58f9cce9a498b2205ac.tar.xz
zsh-ab54bf2baa7c319954e6c58f9cce9a498b2205ac.zip
zsh-workers/7720
Diffstat (limited to 'Completion/Debian')
-rw-r--r--Completion/Debian/_apt-get144
-rw-r--r--Completion/Debian/_apt_arguments230
2 files changed, 341 insertions, 33 deletions
diff --git a/Completion/Debian/_apt-get b/Completion/Debian/_apt-get
index e54bd549b..981cb54c8 100644
--- a/Completion/Debian/_apt-get
+++ b/Completion/Debian/_apt-get
@@ -1,40 +1,118 @@
 #compdef apt-get
 
+local short_bool short_intlevel short_configfile short_arbitem
+local long_bool long_intlevel long_configfile long_arbitem
+local action
+
+short_bool=(h v d b s y f u m)
+short_intlevel=(q)
+short_configfile=(c)
+short_arbitem=(o)
+
+long_bool=(help version download-only compile build simulate just-print recon
+  no-act yes assume-yes fix-broken show-upgraded ignore-missing no-download
+  fix-missing ignore-hold no-upgrade force-yes print-uris)
+long_intlevel=(quiet silent)
+long_configfile=(config-file)
+long_arbitem=(option)
+
+action=(update upgrade install remove dist-upgrade dselect-upgrade clean
+  autoclean check source help)
+
+comp_action='compadd "$expl_action[@]" '"$action"
+
+regex_action=(
+ \(
+    /$'update\0' \|
+    /$'upgrade\0' \|
+    /$'install\0' /$'[^\0]#\0' !'_deb_packages uninstalled "$expl_packages[@]" || _deb_packages installed "$expl_packages[@]" ' \# \|
+    /$'remove\0' /$'[^\0]#\0' !'_deb_packages installed "$expl_packages[@]"' \# \|
+    /$'dist-upgrade\0' \|
+    /$'dselect-upgrade\0' \|
+    /$'clean\0' \|
+    /$'autoclean\0' \|
+    /$'check\0' \|
+    /$'source\0' /$'[^\0]#\0' !'_deb_packages avail "$expl_packages[@]"' \# \|
+    /$'help\0' \|
+    /"[]"	!"$comp_action"
+  \)
+)
+
+_apt_arguments _apt-get_sm "$regex_action[@]"
+
 _apt-get () {
-  # This doesn't handle command line of apt completely since command line
-  # parsing library for apt is too complex to handle by _arguments.
-  _arguments -s \
-    -{,-no-}d --{,no-}download-only \
-    -{,-no-}f --{,no-}fix-broken \
-    -{,-no-}h --{,no-}help \
-    -{,-no-}v --{,no-}version \
-    -{,-no-}m --{,no-}ignore-missing \
-    --{,no-}fix-missing \
-    --{,no-}no-download \
-    \*-{,-no-}q \*--{,no-}{quiet,silent} \
-    -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \
-    -{,-no-}y --{,no-}{yes,assume-yes} \
-    -{,-no-}u --{,no-}show-upgraded \
-    -{,-no-}b --{,no-}{compile,build} \
-    --{,no-}ignore-hold \
-    --{,no-}no-upgrade \
-    --{,no-}force-yes \
-    --{,no-}print-uris \
-    {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \
-    {-o,--option}':Foo\:\:Bar=bar:' \
-    '*::command and packages:_apt-get_args'
-}
+  local tmp1 tmp2
+  local expl_action expl_opt expl_bool expl_configfile expl_packages
+  _description expl_action action
+  _description expl_opt option
+  _description expl_bool 'bool value'
+  _description expl_configfile 'config file'
+  _description expl_packages 'package'
+
+  typeset -A options short_to_option long_to_option
+
+  options=(
+    help		1
+    version		1
+    quiet		-1
+    download-only	1
+    compile		1
+    simulate		1
+    assume-yes		1
+    fix-broken		1
+    show-upgraded	1
+    no-download		1
+    fix-missing		1
+    ignore-hold		1
+    no-upgrade		1
+    force-yes		1
+    print-uris		1
+    config-file		1
+    option		-1
+  )
+
+  short_to_option=(
+    h help
+    v version
+    q quiet
+    d download-only
+    b compile
+    s simulate
+    y assume-yes
+    f fix-broken
+    u show-upgraded
+    m fix-missing
+    c config-file
+    o option
+  )
+
+  long_to_option=(
+    help		help
+    version		version
+    quiet		quiet
+    silent		quiet
+    download-only	download-only
+    compile		compile
+    build		compile
+    simulate		simulate
+    just-print		simulate
+    recon		simulate
+    no-act		simulate
+    yes			assume-yes
+    assume-yes		assume-yes
+    fix-broken		fix-broken
+    show-upgraded	show-upgraded
+    ignore-missing	fix-missing
+    no-download		no-download
+    ignore-hold		ignore-hold
+    no-upgrade		no-upgrade
+    force-yes		force-yes
+    print-uris		print-uris
+    config-file		config-file
+    option		option
+  )
 
-_apt-get_args () {
-  if (( CURRENT == 1 )); then
-    compadd "$@" - update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help
-  else
-    case "$words[1]" in
-      install) _deb_packages uninstalled "$@" || _deb_packages installed "$@";;
-      remove) _deb_packages installed "$@";;
-      *) _deb_packages avail "$@";;
-    esac
-  fi
+  _apt-get_sm
 }
 
 _apt-get "$@"
diff --git a/Completion/Debian/_apt_arguments b/Completion/Debian/_apt_arguments
new file mode 100644
index 000000000..b97a92852
--- /dev/null
+++ b/Completion/Debian/_apt_arguments
@@ -0,0 +1,230 @@
+#autoload
+
+# short_bool=(h v d b s y f u m)
+# short_intlevel=(q)
+# short_configfile=(c)
+# short_arbitem=(o)
+# 
+# long_bool=(help version download-only compile build simulate just-print recon
+#   no-act yes assume-yes fix-broken show-upgraded ignore-missing no-download
+#   fix-missing ignore-hold no-upgrade force-yes print-uris)
+# long_intlevel=(quiet silent)
+# long_configfile=(config-file)
+# long_arbitem=(option)
+
+###
+
+local funcname
+funcname="$1"
+shift
+
+local short_seq false true bool bool_ __bool_ intlevel word word1 nul
+local comp_bool comp_intlevel comp_configfile comp_arbitem comp_long
+local regex_short regex_long regex_message regex_action
+
+regex_action=("$@")
+
+short_seq="(${(j:|:)short_bool}|${(j:|:)short_intlevel})#"
+
+false=(no false without off disable)
+true=(yes true with on enable)
+bool=($false $true)
+
+bool_=(${^bool}-)
+__bool_=(--$^bool_)
+
+intlevel='[0-9]##'
+
+word=$'[^\0]#\0'
+word1=$'[^\0]##\0'
+
+nul=$'\0'
+
+comp_bool='compadd "$expl_bool[@]" '"$bool"
+comp_intlevel= #"_message 'intlevel'"
+comp_configfile='_files "$expl_configfile[@]"'
+comp_arbitem= #"_message 'Foo::Bar=bar'"
+
+comp_long="\
+tmp1=\${(kj:|:)long_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}
+tmp2=(--\${(M)^long_bool:#\$~tmp1} --\${(M)^long_intlevel:#\$~tmp1})
+compadd \"\$expl_opt[@]\" - \$tmp2
+tmp2=(--\${(M)^long_configfile:#\$~tmp1} --\${(M)^long_arbitem:#\$~tmp1})
+compadd \"\$expl_opt[@]\" -S= - \$tmp2
+compadd \"\$expl_opt[@]\" -S '' - $__bool_"
+
+regex_short=(
+  %-
+  \(
+    /"$short_seq(${(j:|:)short_bool})($nul(${(j:|:)bool})|(${(j:|:)bool})|)$nul"
+      -"apt_consume_short \${_ra_match%%($nul(${(j:|:)bool})|(${(j:|:)bool})|)$nul}" \|
+    /"$short_seq(${(j:|:)short_bool})="
+      -"apt_consume_short \${_ra_match%=}"
+      \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \|
+    /"$short_seq(${(j:|:)short_intlevel})($nul$intlevel|$intlevel|)$nul"
+      -"apt_consume_short \${_ra_match%%($nul$intlevel|$intlevel|)$nul}" \|
+    /"$short_seq(${(j:|:)short_intlevel})="
+      -"apt_consume_short \${_ra_match%=}"
+      \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \|
+    /"$short_seq(${(j:|:)short_configfile})(=|)"
+      -"apt_consume_short \${_ra_match%=}"
+      \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \|
+    /"$short_seq(${(j:|:)short_arbitem})(=|)"
+      -"apt_consume_short \${_ra_match%=}"
+      \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \|
+    /"[]" !"{
+	      if [[ \$PREFIX = -$short_seq ]]; then
+		apt_consume_short \${PREFIX[2,-1]}
+		tmp1=(\${(k)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]})
+		tmp2=(-\${^tmp1})
+		compadd \"\$expl_opt[@]\" -y \"(\$tmp2)\" - \${PREFIX}\${^tmp1}
+	      fi
+	      $comp_long
+	    }"
+  \)
+)
+
+regex_long=(
+  %--
+  \(
+    /"(${(j:|:)long_bool})="
+      -"apt_consume_long \${_ra_match%=}"
+      \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \|
+    /"(${(j:|:)long_bool})$nul"
+      -"apt_consume_long \${_ra_match%$nul}"
+      /"((${(j:|:)bool})$nul|)" !"$comp_bool" \|
+    /"(${(j:|:)long_intlevel})="
+      -"apt_consume_long \${_ra_match%=}"
+      \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \|
+    /"(${(j:|:)long_intlevel})$nul"
+      -"apt_consume_long \${_ra_match%$nul}"
+      /"($intlevel$nul|)" !"$comp_intlevel" \|
+    /"(${(j:|:)long_configfile})$nul"
+      -"apt_consume_long \${_ra_match%$nul}"
+      /"$word" !"$comp_configfile" \|
+    /"(${(j:|:)long_configfile})="
+      -"apt_consume_long \${_ra_match%=}"
+      \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \|
+    /"(${(j:|:)long_arbitem})$nul"
+      -"apt_consume_long \${_ra_match%$nul}"
+      /"$word" !"$comp_arbitem" \|
+    /"(${(j:|:)long_arbitem})="
+      -"apt_consume_long \${_ra_match%=}"
+      \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \|
+    %"(${(j:|:)bool})-"
+    \(
+      /"(${(j:|:)long_bool})="
+	-"apt_consume_long \${_ra_match%=}"
+        \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \|
+      /"(${(j:|:)long_bool})$nul"
+	-"apt_consume_long \${_ra_match%$nul}"
+        /"((${(j:|:)bool})$nul|)" !"$comp_bool" \|
+      /"(${(j:|:)long_intlevel})$nul"
+	-"apt_consume_long \${_ra_match%$nul}"
+        /"$intlevel" !"$comp_intlevel" /"$nul" \|
+      /"(${(j:|:)long_intlevel})="
+	-"apt_consume_long \${_ra_match%=}"
+        \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \|
+      /"(${(j:|:)long_intlevel})$nul"
+	-"apt_consume_long \${_ra_match%$nul}"
+        /"($intlevel$nul|)" !"$comp_intlevel" \|
+      /"(${(j:|:)long_configfile})$nul"
+	-"apt_consume_long \${_ra_match%$nul}"
+        /"$word" !"$comp_configfile" \|
+      /"(${(j:|:)long_configfile})="
+	-"apt_consume_long \${_ra_match%=}"
+        \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \|
+      /"(${(j:|:)long_arbitem})$nul"
+	-"apt_consume_long \${_ra_match%$nul}"
+        /"$word" !"$comp_arbitem" \|
+      /"(${(j:|:)long_arbitem})="
+	-"apt_consume_long \${_ra_match%=}"
+        \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \|
+      /"(${(j:|:)short_bool})="
+	-"apt_consume_short \${_ra_match[-2]}"
+        \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \|
+      /"(${(j:|:)short_bool})$nul"
+	-"apt_consume_short \${_ra_match[-2]}"
+        /"((${(j:|:)bool})$nul|)" !"$comp_bool" \|
+      /"(${(j:|:)short_intlevel})="
+	-"apt_consume_short \${_ra_match[-2]}"
+        \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \|
+      /"(${(j:|:)short_intlevel})$nul"
+	-"apt_consume_short \${_ra_match[-2]}"
+        /"($intlevel$nul|)" !"$comp_intlevel" \|
+      /"(${(j:|:)short_configfile})$nul"
+	-"apt_consume_short \${_ra_match[-2]}"
+        /"$word" !"$comp_configfile" \|
+      /"(${(j:|:)short_configfile})="
+	-"apt_consume_short \${_ra_match[-2]}"
+        \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \|
+      /"(${(j:|:)short_arbitem})$nul"
+	-"apt_consume_short \${_ra_match[-2]}"
+        /"$word" !"$comp_arbitem" \|
+      /"(${(j:|:)short_arbitem})="
+	-"apt_consume_short \${_ra_match[-2]}"
+        \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \|
+      /"[]" !"{ tmp1=\${(kj:|:)long_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}
+		tmp2=(\$_ra_left\${(M)^long_bool:#\$~tmp1} \$_ra_left\${(M)^long_intlevel:#\$~tmp1})
+		compadd \"\$expl_opt[@]\" - \$tmp2
+		tmp2=(\$_ra_left\${(M)^long_configfile:#\$~tmp1} \$_ra_left\${(M)^long_arbitem:#\$~tmp1})
+		compadd \"\$expl_opt[@]\" -S= - \$tmp2
+		tmp1=\${(kj:|:)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}
+		tmp2=(\$_ra_left\${(M)^short_bool:#\$~tmp1} \$_ra_left\${(M)^short_intlevel:#\$~tmp1})
+		compadd \"\$expl_opt[@]\" - \$tmp2
+		tmp2=(\$_ra_left\${(M)^short_configfile:#\$~tmp1} \$_ra_left\${(M)^short_arbitem:#\$~tmp1})
+		compadd \"\$expl_opt[@]\" -S= - \$tmp2
+	      }"
+    \) \|
+    /"[]" !"{
+	      $comp_long
+	    }"
+  \)
+)
+
+regex_message=(
+  /"[]" !"[[ -prefix - || -z \"\$compconfig[option_prefix]\" ]] && {
+	    if [[ \$PREFIX = -$short_seq ]]; then
+	      apt_consume_short \${PREFIX[2,-1]}
+	      tmp1=(\${(k)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]})
+	      tmp2=(-\${^tmp1})
+	      compadd \"\$expl_opt[@]\" -y \"(\$tmp2)\" - \${PREFIX}\${^tmp1}
+	    elif [[ -z "\$PREFIX" ]]; then
+	      tmp1=(-\${(k)^short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]})
+	      compadd \"\$expl_opt[@]\" - \$tmp1
+	    fi
+	    $comp_long
+	  }"
+)
+
+apt_consume_short () {
+  local short opt
+  for short in ${(s::)1}; do
+    opt="$short_to_option[$short]"
+    (( 0 < options[$opt] && options[$opt]-- ))
+  done
+}
+
+apt_consume_long () {
+  local long opt
+  opt="$long_to_option[$1]"
+  (( 0 < options[$opt] && options[$opt]-- ))
+}
+
+_regex_arguments "${funcname}_sm" /"$word" \( "$regex_long[@]" \| "$regex_short[@]" \| "$regex_message[@]" \) \# "$regex_action[@]"
+
+eval "$funcname () {
+  local short_bool short_intlevel short_configfile short_arbitem
+  local long_bool long_intlevel long_configfile long_arbitem
+  short_bool=($short_bool)
+  short_intlevel=($short_intlevel)
+  short_configfile=($short_configfile)
+  short_arbitem=($short_arbitem)
+  long_bool=($long_bool)
+  long_intlevel=($long_intlevel)
+  long_configfile=($long_configfile)
+  long_arbitem=($long_arbitem)
+
+  ${funcname}_sm
+}"
+