style fixes to previous commit

This commit addresses many of the style problems with the previous
commit. If this introduces any bugs they are solely my fault. The style
of this code needs more improvement. Some of which could be done today.
Others will have to wait until `fish_indent` is improved.
This commit is contained in:
Kurtis Rader 2017-02-01 22:49:40 -08:00
parent eff6b98813
commit 088b10f4c2
4 changed files with 70 additions and 106 deletions

View file

@ -1,7 +1,6 @@
# #
# Load common ssh options # Load completions shared by ssh and scp.
# #
__fish_complete_ssh scp __fish_complete_ssh scp
# #
@ -11,11 +10,7 @@ __fish_complete_ssh scp
# #
# Hostname # Hostname
# #
complete \ complete -c scp -d Hostname -n "commandline --cut-at-cursor --current-token | string match -v '*:*'" -a "
--command scp \
--description Hostname \
--condition "commandline --cut-at-cursor --current-token | string match --invert '*:*'" \
--arguments "
(__fish_print_hostnames): (__fish_print_hostnames):
@ -23,29 +18,17 @@ complete \
#Prepend any username specified in the completion to the hostname #Prepend any username specified in the completion to the hostname
commandline -ct |sed -ne 's/\(.*@\).*/\1/p' commandline -ct |sed -ne 's/\(.*@\).*/\1/p'
)(__fish_print_hostnames): )(__fish_print_hostnames):
# Disable as username completion is not very useful
# (__fish_print_users)@\tUsername
" "
# #
# Local path # Local path
# #
complete \ complete -c scp -d "Local Path" -n "commandline -ct | string match ':'"
--command scp \
--description "Local Path" \
--condition "commandline -ct | string match ':'"
# #
# Remote path # Remote path
# #
complete \ complete -c scp -d "Remote Path" -f -n "commandline --cut-at-cursor --current-token | string match -r '.+:'" -a "
--command scp \
--description "Remote Path" \
--no-files \
--condition "commandline --cut-at-cursor --current-token | string match --regex '.+:'" \
--arguments "
( (
#Prepend any user@host information supplied before the remote completion #Prepend any user@host information supplied before the remote completion
@ -56,11 +39,10 @@ complete \
) )
" "
complete -c scp -s B -d "Batch mode"
complete -c scp -s B --description "Batch mode" complete -c scp -s l -x -d "Bandwidth limit"
complete -c scp -s l -x --description "Bandwidth limit" complete -c scp -s P -x -d "Port"
complete -c scp -s P -x --description "Port" complete -c scp -s p -d "Preserves modification times, access times, and modes from the original file"
complete -c scp -s p --description "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 q --description "Do not display progress bar" complete -c scp -s r -d "Recursively copy"
complete -c scp -s r --description "Recursively copy" complete -c scp -s S -d "Encryption program"
complete -c scp -s S --description "Encryption program"

View file

@ -1,50 +1,50 @@
# #
# Load common ssh options # Load completions shared by ssh and scp.
# #
__fish_complete_ssh ssh __fish_complete_ssh ssh
#
# ssh specific completions
#
complete -x -c ssh -d Hostname -a " complete -x -c ssh -d Hostname -a "
(__fish_print_hostnames) (__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' echo (commandline -ct)|sed -ne 's/\(.*@\).*/\1/p'
)(__fish_print_hostnames) )(__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 " # complete -x -c ssh -d User -a "
# (__fish_print_users | string match -r -v '^_')@ # (__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 -d "Command to run" -x -a '(__fish_complete_subcommand --fcs-skip=2)'
complete -c ssh -s A --description "Enables forwarding of the authentication agent"
complete -x -c ssh -s b --description "Interface to transmit from" -a " 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 /proc/net/arp is not POSIX compliant # TODO: Improve this since /proc/net/arp is not POSIX compliant.
cut -d ' ' -f 1 /proc/net/arp ^/dev/null | string match -r -v '^IP' 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 -x -c ssh -s e -d "Escape character" -a "\^ none"
complete -c ssh -s f --description "Go to background" complete -c ssh -s f -d "Go to background"
complete -c ssh -s g --description "Allow remote host to connect to local forwarded ports" complete -c ssh -s g -d "Allow remote host to connect to local forwarded ports"
complete -c ssh -s I --description "Smartcard device" complete -c ssh -s I -d "Smartcard device"
complete -c ssh -s k --description "Disable forwarding of Kerberos tickets" complete -c ssh -s k -d "Disable forwarding of Kerberos tickets"
complete -c ssh -s l -x -a "(__fish_complete_users)" --description "User" complete -c ssh -s l -x -a "(__fish_complete_users)" -d "User"
complete -c ssh -s m --description "MAC algorithm" complete -c ssh -s m -d "MAC algorithm"
complete -c ssh -s n --description "Prevent reading from stdin" complete -c ssh -s n -d "Prevent reading from stdin"
complete -c ssh -s N --description "Do not execute remote command" complete -c ssh -s N -d "Do not execute remote command"
complete -c ssh -s p -x --description "Port" complete -c ssh -s p -x -d "Port"
complete -c ssh -s q --description "Quiet mode" complete -c ssh -s q -d "Quiet mode"
complete -c ssh -s s --description "Subsystem" complete -c ssh -s s -d "Subsystem"
complete -c ssh -s t --description "Force pseudo-tty allocation" complete -c ssh -s t -d "Force pseudo-tty allocation"
complete -c ssh -s T --description "Disable pseudo-tty allocation" complete -c ssh -s T -d "Disable pseudo-tty allocation"
complete -c ssh -s x --description "Disable X11 forwarding" complete -c ssh -s x -d "Disable X11 forwarding"
complete -c ssh -s X --description "Enable X11 forwarding" complete -c ssh -s X -d "Enable X11 forwarding"
complete -c ssh -s L --description "Locally forwarded ports" complete -c ssh -s L -d "Locally forwarded ports"
complete -c ssh -s R --description "Remotely forwarded ports" complete -c ssh -s R -d "Remotely forwarded ports"
complete -c ssh -s D --description "Dynamic port forwarding" complete -c ssh -s D -d "Dynamic port forwarding"

View file

@ -1,15 +1,13 @@
function __fish_complete_ssh -d "common completions for ssh commands" --argument command function __fish_complete_ssh -d "common completions for ssh commands" --argument command
complete -c $command -s 1 -d "Protocol version 1 only"
complete -c $command -s 1 --description "Protocol version 1 only" complete -c $command -s 2 -d "Protocol version 2 only"
complete -c $command -s 2 --description "Protocol version 2 only" complete -c $command -s 4 -d "IPv4 addresses only"
complete -c $command -s 4 --description "IPv4 addresses only" complete -c $command -s 6 -d "IPv6 addresses only"
complete -c $command -s 6 --description "IPv6 addresses only" complete -c $command -s C -d "Compress all data"
complete -c $command -s C --description "Compress all data" complete -xc $command -s c -d "Encryption algorithm" -a "blowfish 3des des"
complete -xc $command -s c --description "Encryption algorithm" -a "blowfish 3des des" complete -r -c $command -s F -d "Configuration file"
complete -r -c $command -s F --description "Configuration file" complete -r -c $command -s i -d "Identity file"
complete -r -c $command -s i --description "Identity file" complete -x -c $command -s o -d "Options" -a "
complete -x -c $command -s o --description "Options" -a "
AddressFamily AddressFamily
BatchMode BatchMode
BindAddress BindAddress
@ -56,6 +54,5 @@ function __fish_complete_ssh -d "common completions for ssh commands" --argument
UserKnownHostsFile UserKnownHostsFile
VerifyHostKeyDNS VerifyHostKeyDNS
" "
complete -c $command -s v --description "Verbose mode" complete -c $command -s v -d "Verbose mode"
end end

View file

@ -1,23 +1,15 @@
function __fish_print_hostnames -d "Print a list of known hostnames" function __fish_print_hostnames -d "Print a list of known hostnames"
# Print all hosts from /etc/hosts # Print all hosts from /etc/hosts. Use 'getent hosts' on OSes that support it
# use 'getent hosts' on OSes that support it (OpenBSD and Cygwin do not) # (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 # Test if 'getent hosts' works and redirect output so errors don't print.
getent hosts | string match --regex --invert '^0.0.0.0' \ if type -q getent
# Remove left addresses column and getent hosts >/dev/null 2>&1
| string replace --regex '^\s*\S+\s+' '' \ # Ignore zero IPs.
# Tokenize remaining hostnames and aliases columnss getent hosts | string match -r -v '^0.0.0.0' | string replace -r '^\s*\S+\s+' '' | string split ' '
| string split ' '
else if test -r /etc/hosts else if test -r /etc/hosts
# Ignore commented lines and functionally empty lines # Ignore commented lines and functionally empty lines.
string match --regex --invert '^\s*0.0.0.0|^\s*#|^\s*$' </etc/hosts \ string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' </etc/hosts | string replace -r -a '#.*$' '' | string replace -r '^\s*\S+\s+' '' | string trim | string replace -r -a '\s+' ' ' | string split ' '
# Strip comments
| string replace --regex --all '#.*$' '' \
# Remove left addresses column
| string replace --regex '^\s*\S+\s+' '' \
# Tokenize remaining hostnames and aliases columns
| string trim | string replace --regex --all '\s+' ' ' | string split ' '
end end
# Print nfs servers from /etc/fstab # Print nfs servers from /etc/fstab
@ -61,18 +53,18 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
for config in $argv for config in $argv
set paths $paths (cat $config ^/dev/null \ set paths $paths (cat $config ^/dev/null \
# Keep only Include lines # Keep only Include lines
| string match --regex --ignore-case '^\s*Include\s+.+' \ | string match -r -i '^\s*Include\s+.+' \
# Remove Include syntax # Remove Include syntax
| string replace --regex --ignore-case '^\s*Include\s+' '' \ | string replace -r -i '^\s*Include\s+' '' \
# Normalize whitespace # Normalize whitespace
| string trim | string replace --regex --all '\s+' ' ') | string trim | string replace -r -a '\s+' ' ')
end end
if test -n "$paths" if test -n "$paths"
# Expand paths which may have globbing and tokenize # Expand paths which may have globbing and tokenize
set paths (eval "echo $paths" | string split ' ') set paths (eval "echo $paths" | string split ' ')
for path_index in (seq (count $paths)) for path_index in (seq (count $paths))
# Resolve relative paths # Resolve relative paths
if string match --invert '/*' $paths[$path_index] >/dev/null if string match -v '/*' $paths[$path_index] >/dev/null
set paths[$path_index] $relative_path/$paths[$path_index] set paths[$path_index] $relative_path/$paths[$path_index]
end end
echo $paths[$path_index] echo $paths[$path_index]
@ -87,16 +79,9 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
for file in $ssh_configs for file in $ssh_configs
if test -r $file if test -r $file
# Print hosts from system wide ssh configuration file # Print hosts from system wide ssh configuration file
string match --regex --ignore-case '^\s*Host\s+\S+' <$file \ 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 '*\**'
# We only want the value(s) # Extract known_host paths.
| string replace --regex --ignore-case '^\s*Host\s+' '' \ set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' <$file | string replace -ri '.*KnownHostsFile\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*' '')
end end
end end
for file in $known_hosts for file in $known_hosts