about summary refs log tree commit diff
path: root/Completion/Debian
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Debian')
-rw-r--r--Completion/Debian/_apt_arguments230
1 files changed, 230 insertions, 0 deletions
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
+}"
+