2005-09-20 21:31:55 +08:00
|
|
|
#
|
2017-02-02 14:49:40 +08:00
|
|
|
# Load completions shared by ssh and scp.
|
2005-09-20 21:31:55 +08:00
|
|
|
#
|
2006-02-15 10:22:28 +08:00
|
|
|
__fish_complete_ssh scp
|
2005-09-20 21:31:55 +08:00
|
|
|
|
2017-04-15 14:21:17 +08:00
|
|
|
# Helper functions to simplify the completions.
|
|
|
|
function __scp2ssh_port_number
|
|
|
|
# There is a silly inconsistency between the ssh and scp commands regarding the short flag name
|
|
|
|
# for specifying the TCP port number. This function deals with that by extracting the port
|
|
|
|
# number if present and emitting it as a flag appropriate for ssh.
|
|
|
|
set -l port (commandline -c | string match -r -- ' -P ?(\d+)\b')
|
|
|
|
and echo -p\n$port[2]
|
|
|
|
end
|
|
|
|
|
|
|
|
function __scp_remote_target
|
|
|
|
set -l target (commandline -ct | string match -r -- '(.*):')
|
|
|
|
and echo $target[2]
|
|
|
|
end
|
|
|
|
|
|
|
|
function __scp_remote_path_prefix
|
|
|
|
set -l path_prefix (commandline -ct | string match -r -- ':(.*)')
|
|
|
|
and echo $path_prefix[2]
|
|
|
|
end
|
|
|
|
|
2005-09-20 21:31:55 +08:00
|
|
|
#
|
|
|
|
# scp specific completions
|
|
|
|
#
|
|
|
|
|
2017-01-26 10:03:36 +08:00
|
|
|
#
|
|
|
|
# Hostname
|
|
|
|
#
|
2017-02-02 14:49:40 +08:00
|
|
|
complete -c scp -d Hostname -n "commandline --cut-at-cursor --current-token | string match -v '*:*'" -a "
|
2017-11-08 19:52:16 +08:00
|
|
|
(__fish_complete_user_at_hosts):"
|
2012-07-12 08:20:58 +08:00
|
|
|
|
2017-01-26 10:03:36 +08:00
|
|
|
#
|
|
|
|
# Local path
|
|
|
|
#
|
2017-02-02 14:49:40 +08:00
|
|
|
complete -c scp -d "Local Path" -n "commandline -ct | string match ':'"
|
2017-01-26 10:03:36 +08:00
|
|
|
|
2012-07-12 08:20:58 +08:00
|
|
|
#
|
|
|
|
# Remote path
|
|
|
|
#
|
2017-02-02 14:49:40 +08:00
|
|
|
complete -c scp -d "Remote Path" -f -n "commandline --cut-at-cursor --current-token | string match -r '.+:'" -a "
|
2017-04-15 14:21:17 +08:00
|
|
|
(__scp_remote_target):(
|
|
|
|
# Get the list of remote files from the scp target.
|
|
|
|
ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null
|
2012-07-12 08:20:58 +08:00
|
|
|
)
|
|
|
|
"
|
2017-02-02 14:49:40 +08:00
|
|
|
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"
|