Przeglądaj źródła

Add some shell completions

Benjamin Sago 4 lat temu
rodzic
commit
e0389e2968
3 zmienionych plików z 117 dodań i 0 usunięć
  1. 48 0
      completions/dog.bash
  2. 43 0
      completions/dog.fish
  3. 26 0
      completions/dog.zsh

+ 48 - 0
completions/dog.bash

@@ -0,0 +1,48 @@
+_dog()
+{
+    cur=${COMP_WORDS[COMP_CWORD]}
+    prev=${COMP_WORDS[COMP_CWORD-1]}
+
+    case "$prev" in
+        -'?'|--help|-v|--version)
+            return
+            ;;
+
+        -t|--type)
+            COMPREPLY=( $( compgen -W 'A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT' -- "$cur" ) )
+            return
+            ;;
+
+        --edns)
+            COMPREPLY=( $( compgen -W 'disable hide show' -- "$cur" ) )
+            return
+            ;;
+
+        -Z)
+            COMPREPLY=( $( compgen -W 'authentic' -- "$cur" ) )
+            return
+            ;;
+
+        --class)
+            COMPREPLY=( $( compgen -W 'IN CH HS' -- "$cur" ) )
+            return
+            ;;
+
+        --color|--colour)
+            COMPREPLY=( $( compgen -W 'always automatic never' -- $cur ) )
+            return
+            ;;
+    esac
+
+    case "$cur" in
+        -*)
+            COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
+            return
+            ;;
+
+        *)
+            COMPREPLY=( $( compgen -W 'A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT' -- "$cur" ) )
+            ;;
+    esac
+} &&
+complete -o bashdefault -F _dog dog

+ 43 - 0
completions/dog.fish

@@ -0,0 +1,43 @@
+# Meta options
+complete -c dog -s 'v' -l 'version' -d "Show version of dog"
+complete -c dog -s '?' -l 'help'    -d "Show list of command-line options"
+
+# Query options
+complete -c dog -x -a "(__fish_print_hostnames) A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT IN CH HS"
+complete -c dog -s 'q' -l 'query'      -d "Host name or IP address to query" -x -a "(__fish_print_hostnames)"
+complete -c dog -s 't' -l 'type'       -d "Type of the DNS record being queried" -x -a "A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT"
+complete -c dog -s 'n' -l 'nameserver' -d "Address of the nameserver to send packets to" -x -a "(__fish_print_hostnames)"
+complete -c dog        -l 'class'      -d "Network class of the DNS record being queried" -x -a "IN CH HS"
+
+# Sending options
+complete -c dog        -l 'edns'       -d "Whether to OPT in to EDNS" -x -a "
+    disable\t'Do not send an OPT query'
+    hide\t'Send an OPT query, but hide the result'
+    show\t'Send an OPT query, and show the result'
+"
+complete -c dog        -l 'txid'       -d "Set the transaction ID to a specific value" -x
+complete -c dog -s 'Z'                 -d "Configure uncommon protocol tweaks" -x -a "
+    authentic\t'Set the AD (Authentic Data) query bit'
+"
+
+# Protocol options
+complete -c dog -s 'U' -l 'udp'        -d "Use the DNS protocol over UDP"
+complete -c dog -s 'T' -l 'tcp'        -d "Use the DNS protocol over TCP"
+complete -c dog -s 'S' -l 'tls'        -d "Use the DNS-over-TLS protocol"
+complete -c dog -s 'H' -l 'https'      -d "Use the DNS-over-HTTPS protocol"
+
+# Output options
+complete -c dog -s '1' -l 'short'      -d "Display nothing but the first result"
+complete -c dog -s 'J' -l 'json'       -d "Display the output as JSON"
+complete -c dog        -l 'color'      -d "When to colorise the output" -x -a "
+    always\t'Always use colors'
+    automatic\t'Use colors when printing to a terminal'
+    never\t'Never use colors'
+"
+complete -c dog        -l 'colour'     -d "When to colourise the output" -x -a "
+    always\t'Always use colours'
+    automatic\t'Use colours when printing to a terminal'
+    never\t'Never use colours'
+"
+complete -c dog        -l 'seconds'    -d "Do not format durations, display them as seconds"
+complete -c dog        -l 'time'       -d "Print how long the response took to arrive"

+ 26 - 0
completions/dog.zsh

@@ -0,0 +1,26 @@
+#compdef dog
+
+__dog() {
+    _arguments \
+        "(- 1 *)"{-v,--version}"[Show version of dog]" \
+        "(- 1 *)"{-\?,--help}"[Show list of command-line options]" \
+        {-q,--query}"[Host name or IP address to query]::_hosts" \
+        {-t,--type}"[Type of the DNS record being queried]:(record type):(A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT)" \
+        {-n,--nameserver}"[Address of the nameserver to send packets to]::_hosts;" \
+        --class"[Network class of the DNS record being queried]:(network class):(IN CH HS)" \
+        --edns"[Whether to OPT in to EDNS]:(edns setting):(disable hide show)" \
+        --txid"[Set the transaction ID to a specific value]" \
+        -Z"[Configure uncommon protocol tweaks]" \
+        {-U,--udp}"[Use the DNS protocol over UDP]" \
+        {-T,--tcp}"[Use the DNS protocol over TCP]" \
+        {-S,--tls}"[Use the DNS-over-TLS protocol]" \
+        {-H,--https}"[Use the DNS-over-HTTPS protocol]" \
+        {-1,--short}"[Display nothing but the finst result]" \
+        {-J,--json}"[Display the output as JSON]" \
+        {--color,--colour}"[When to use terminal colours]:(setting):(always automatic never)" \
+        --seconds"[Do not format durations, display them as seconds]" \
+        --time"[Print how long the response took to arrive"] \
+        '*:filename:_hosts'
+}
+
+__dog