2021-03-16 18:48:10 +00:00
|
|
|
# Load completions shared by various ssh tools like ssh, scp and sftp.
|
2006-02-15 02:22:28 +00:00
|
|
|
__fish_complete_ssh scp
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2021-03-16 18:48:10 +00:00
|
|
|
|
2017-04-15 06:21:17 +00: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
|
|
|
|
|
2018-06-04 12:30:49 +00:00
|
|
|
function __fish_no_scp_remote_specified
|
|
|
|
set -l tokens (commandline -t)
|
|
|
|
# can't use `for token in tokens[1..-2]` due to https://github.com/fish-shell/fish-shell/issues/4897
|
|
|
|
set -e tokens[-1]
|
|
|
|
for token in $tokens # ignoring current token
|
|
|
|
if string match -e @ -- $token
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2005-09-20 13:31:55 +00:00
|
|
|
#
|
|
|
|
# scp specific completions
|
|
|
|
#
|
|
|
|
|
2017-01-26 02:03:36 +00:00
|
|
|
#
|
2018-06-04 12:30:49 +00:00
|
|
|
# Inherit user/host completions from ssh
|
2017-01-26 02:03:36 +00:00
|
|
|
#
|
2018-06-04 12:30:49 +00:00
|
|
|
complete -c scp -d Remote -n "__fish_no_scp_remote_specified; and not string match -e : (commandline -ct)" -a "(complete -C'ssh ' | string replace -r '\t.*' ':')"
|
2012-07-12 00:20:58 +00:00
|
|
|
|
2017-01-26 02:03:36 +00:00
|
|
|
#
|
|
|
|
# Local path
|
|
|
|
#
|
2018-06-04 12:30:49 +00:00
|
|
|
complete -c scp -d "Local Path" -n "not string match @ -- (commandline -ct)"
|
2017-01-26 02:03:36 +00:00
|
|
|
|
2012-07-12 00:20:58 +00:00
|
|
|
#
|
|
|
|
# Remote path
|
|
|
|
#
|
2018-06-04 12:30:49 +00:00
|
|
|
# Get the list of remote files from the scp target.
|
2019-10-30 12:00:17 +00:00
|
|
|
complete -c scp -d "Remote Path" -f -n "commandline -ct | string match -e ':'" -a "
|
2018-06-04 12:30:49 +00:00
|
|
|
(__scp_remote_target):( \
|
2022-11-20 12:40:58 +00:00
|
|
|
command ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) command\ ls\ -dp\ (__scp_remote_path_prefix | string unescape)\* 2>/dev/null |
|
2020-01-13 09:18:43 +00:00
|
|
|
string escape -n
|
2012-07-12 00:20:58 +00:00
|
|
|
)
|
|
|
|
"
|
2021-03-16 18:48:10 +00:00
|
|
|
complete -c scp -s 3 -d "Copies between two remote hosts are transferred through the local host"
|
2017-02-02 06:49:40 +00:00
|
|
|
complete -c scp -s B -d "Batch mode"
|
2022-06-24 18:14:35 +00:00
|
|
|
complete -c scp -s D -x -d "Connect directly to a local SFTP server"
|
2017-02-02 06:49:40 +00:00
|
|
|
complete -c scp -s l -x -d "Bandwidth limit"
|
2022-06-24 18:14:35 +00:00
|
|
|
complete -c scp -s O -d "Use original SCP protocol instead of SFTP"
|
2020-03-09 18:36:12 +00:00
|
|
|
complete -c scp -s P -x -d Port
|
2017-02-02 06:49:40 +00:00
|
|
|
complete -c scp -s p -d "Preserves modification times, access times, and modes from the original file"
|
2022-06-24 18:14:35 +00:00
|
|
|
complete -c scp -s R -d "Copies between two remote hosts are performed by executing scp on the origin host"
|
2017-02-02 06:49:40 +00:00
|
|
|
complete -c scp -s r -d "Recursively copy"
|
|
|
|
complete -c scp -s S -d "Encryption program"
|
2021-03-16 18:48:10 +00:00
|
|
|
complete -c scp -s T -d "Disable strict filename checking"
|