diff --git a/share/completions/scp.fish b/share/completions/scp.fish index 0b14ceaad..528cdcec3 100644 --- a/share/completions/scp.fish +++ b/share/completions/scp.fish @@ -1,7 +1,6 @@ # -# Load common ssh options +# Load completions shared by ssh and scp. # - __fish_complete_ssh scp # @@ -11,11 +10,7 @@ __fish_complete_ssh scp # # Hostname # -complete \ - --command scp \ - --description Hostname \ - --condition "commandline --cut-at-cursor --current-token | string match --invert '*:*'" \ - --arguments " +complete -c scp -d Hostname -n "commandline --cut-at-cursor --current-token | string match -v '*:*'" -a " (__fish_print_hostnames): @@ -23,29 +18,17 @@ complete \ #Prepend any username specified in the completion to the hostname commandline -ct |sed -ne 's/\(.*@\).*/\1/p' )(__fish_print_hostnames): - -# Disable as username completion is not very useful -# (__fish_print_users)@\tUsername - " # # Local path # -complete \ - --command scp \ - --description "Local Path" \ - --condition "commandline -ct | string match ':'" +complete -c scp -d "Local Path" -n "commandline -ct | string match ':'" # # Remote path # -complete \ - --command scp \ - --description "Remote Path" \ - --no-files \ - --condition "commandline --cut-at-cursor --current-token | string match --regex '.+:'" \ - --arguments " +complete -c scp -d "Remote Path" -f -n "commandline --cut-at-cursor --current-token | string match -r '.+:'" -a " ( #Prepend any user@host information supplied before the remote completion @@ -56,11 +39,10 @@ complete \ ) " - -complete -c scp -s B --description "Batch mode" -complete -c scp -s l -x --description "Bandwidth limit" -complete -c scp -s P -x --description "Port" -complete -c scp -s p --description "Preserves modification times, access times, and modes from the original file" -complete -c scp -s q --description "Do not display progress bar" -complete -c scp -s r --description "Recursively copy" -complete -c scp -s S --description "Encryption program" +complete -c scp -s B -d "Batch mode" +complete -c scp -s l -x -d "Bandwidth limit" +complete -c scp -s P -x -d "Port" +complete -c scp -s p -d "Preserves modification times, access times, and modes from the original file" +complete -c scp -s q -d "Do not display progress bar" +complete -c scp -s r -d "Recursively copy" +complete -c scp -s S -d "Encryption program" diff --git a/share/completions/ssh.fish b/share/completions/ssh.fish index 10205d1f9..f9f4dc328 100644 --- a/share/completions/ssh.fish +++ b/share/completions/ssh.fish @@ -1,50 +1,50 @@ # -# Load common ssh options +# Load completions shared by ssh and scp. # - __fish_complete_ssh ssh +# +# ssh specific completions +# complete -x -c ssh -d Hostname -a " - (__fish_print_hostnames) ( - #Prepend any username specified in the completion to the hostname + # Prepend any username specified in the completion to the hostname echo (commandline -ct)|sed -ne 's/\(.*@\).*/\1/p' )(__fish_print_hostnames) " -# Disable as username completion is not very useful +# Disable as username completion is not very useful. # complete -x -c ssh -d User -a " # (__fish_print_users | string match -r -v '^_')@ # " -complete -c ssh --description "Command to run" -x -a '(__fish_complete_subcommand --fcs-skip=2)' -complete -c ssh -s a --description "Disables forwarding of the authentication agent" -complete -c ssh -s A --description "Enables forwarding of the authentication agent" -complete -x -c ssh -s b --description "Interface to transmit from" -a " -( - # TODO /proc/net/arp is not POSIX compliant - cut -d ' ' -f 1 /proc/net/arp ^/dev/null | string match -r -v '^IP' -) +complete -c ssh -d "Command to run" -x -a '(__fish_complete_subcommand --fcs-skip=2)' + +complete -c ssh -s a -d "Disables forwarding of the authentication agent" +complete -c ssh -s A -d "Enables forwarding of the authentication agent" +# TODO: Improve this since /proc/net/arp is not POSIX compliant. +complete -x -c ssh -s b -d "Interface to transmit from" -a " +(cut -d ' ' -f 1 /proc/net/arp ^/dev/null | string match -r -v '^IP') " -complete -x -c ssh -s e --description "Escape character" -a "\^ none" -complete -c ssh -s f --description "Go to background" -complete -c ssh -s g --description "Allow remote host to connect to local forwarded ports" -complete -c ssh -s I --description "Smartcard device" -complete -c ssh -s k --description "Disable forwarding of Kerberos tickets" -complete -c ssh -s l -x -a "(__fish_complete_users)" --description "User" -complete -c ssh -s m --description "MAC algorithm" -complete -c ssh -s n --description "Prevent reading from stdin" -complete -c ssh -s N --description "Do not execute remote command" -complete -c ssh -s p -x --description "Port" -complete -c ssh -s q --description "Quiet mode" -complete -c ssh -s s --description "Subsystem" -complete -c ssh -s t --description "Force pseudo-tty allocation" -complete -c ssh -s T --description "Disable pseudo-tty allocation" -complete -c ssh -s x --description "Disable X11 forwarding" -complete -c ssh -s X --description "Enable X11 forwarding" -complete -c ssh -s L --description "Locally forwarded ports" -complete -c ssh -s R --description "Remotely forwarded ports" -complete -c ssh -s D --description "Dynamic port forwarding" +complete -x -c ssh -s e -d "Escape character" -a "\^ none" +complete -c ssh -s f -d "Go to background" +complete -c ssh -s g -d "Allow remote host to connect to local forwarded ports" +complete -c ssh -s I -d "Smartcard device" +complete -c ssh -s k -d "Disable forwarding of Kerberos tickets" +complete -c ssh -s l -x -a "(__fish_complete_users)" -d "User" +complete -c ssh -s m -d "MAC algorithm" +complete -c ssh -s n -d "Prevent reading from stdin" +complete -c ssh -s N -d "Do not execute remote command" +complete -c ssh -s p -x -d "Port" +complete -c ssh -s q -d "Quiet mode" +complete -c ssh -s s -d "Subsystem" +complete -c ssh -s t -d "Force pseudo-tty allocation" +complete -c ssh -s T -d "Disable pseudo-tty allocation" +complete -c ssh -s x -d "Disable X11 forwarding" +complete -c ssh -s X -d "Enable X11 forwarding" +complete -c ssh -s L -d "Locally forwarded ports" +complete -c ssh -s R -d "Remotely forwarded ports" +complete -c ssh -s D -d "Dynamic port forwarding" diff --git a/share/functions/__fish_complete_ssh.fish b/share/functions/__fish_complete_ssh.fish index 00545dcc7..7f3ae4056 100644 --- a/share/functions/__fish_complete_ssh.fish +++ b/share/functions/__fish_complete_ssh.fish @@ -1,15 +1,13 @@ - function __fish_complete_ssh -d "common completions for ssh commands" --argument command - - complete -c $command -s 1 --description "Protocol version 1 only" - complete -c $command -s 2 --description "Protocol version 2 only" - complete -c $command -s 4 --description "IPv4 addresses only" - complete -c $command -s 6 --description "IPv6 addresses only" - complete -c $command -s C --description "Compress all data" - complete -xc $command -s c --description "Encryption algorithm" -a "blowfish 3des des" - complete -r -c $command -s F --description "Configuration file" - complete -r -c $command -s i --description "Identity file" - complete -x -c $command -s o --description "Options" -a " + complete -c $command -s 1 -d "Protocol version 1 only" + complete -c $command -s 2 -d "Protocol version 2 only" + complete -c $command -s 4 -d "IPv4 addresses only" + complete -c $command -s 6 -d "IPv6 addresses only" + complete -c $command -s C -d "Compress all data" + complete -xc $command -s c -d "Encryption algorithm" -a "blowfish 3des des" + complete -r -c $command -s F -d "Configuration file" + complete -r -c $command -s i -d "Identity file" + complete -x -c $command -s o -d "Options" -a " AddressFamily BatchMode BindAddress @@ -56,6 +54,5 @@ function __fish_complete_ssh -d "common completions for ssh commands" --argument UserKnownHostsFile VerifyHostKeyDNS " - complete -c $command -s v --description "Verbose mode" + complete -c $command -s v -d "Verbose mode" end - diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index c9f5bd23e..898512415 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -1,23 +1,15 @@ - function __fish_print_hostnames -d "Print a list of known hostnames" - # Print all hosts from /etc/hosts - # use 'getent hosts' on OSes that support it (OpenBSD and Cygwin do not) - if type -q getent; and getent hosts >/dev/null 2>&1 # test if 'getent hosts' works and redirect output so errors don't print - # Ignore zero ips - getent hosts | string match --regex --invert '^0.0.0.0' \ - # Remove left addresses column - | string replace --regex '^\s*\S+\s+' '' \ - # Tokenize remaining hostnames and aliases columnss - | string split ' ' + # Print all hosts from /etc/hosts. Use 'getent hosts' on OSes that support it + # (OpenBSD and Cygwin do not). + # + # Test if 'getent hosts' works and redirect output so errors don't print. + if type -q getent + and getent hosts >/dev/null 2>&1 + # Ignore zero IPs. + getent hosts | string match -r -v '^0.0.0.0' | string replace -r '^\s*\S+\s+' '' | string split ' ' else if test -r /etc/hosts - # Ignore commented lines and functionally empty lines - string match --regex --invert '^\s*0.0.0.0|^\s*#|^\s*$' /dev/null + if string match -v '/*' $paths[$path_index] >/dev/null set paths[$path_index] $relative_path/$paths[$path_index] end echo $paths[$path_index] @@ -87,16 +79,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames" for file in $ssh_configs if test -r $file # Print hosts from system wide ssh configuration file - string match --regex --ignore-case '^\s*Host\s+\S+' <$file \ - # We only want the value(s) - | string replace --regex --ignore-case '^\s*Host\s+' '' \ - # Print one per line - | string trim | string replace --regex '\s+' ' ' | string split ' ' \ - # Ignore hosts with a glob - | string match --invert '*\**' - # Extract known_host paths - set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' <$file \ - | string replace -ri '.*KnownHostsFile\s*' '') + string match -r -i '^\s*Host\s+\S+' <$file | string replace -r -i '^\s*Host\s+' '' | string trim | string replace -r '\s+' ' ' | string split ' ' | string match -v '*\**' + # Extract known_host paths. + set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' <$file | string replace -ri '.*KnownHostsFile\s*' '') end end for file in $known_hosts