Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (58 sloc) 2.1 KB
# Load completions shared by ssh and scp.
__fish_complete_ssh scp
# 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]
function __scp_remote_target
set -l target (commandline -ct | string match -r -- '(.*):')
and echo $target[2]
function __scp_remote_path_prefix
set -l path_prefix (commandline -ct | string match -r -- ':(.*)')
and echo $path_prefix[2]
function __fish_no_scp_remote_specified
set -l tokens (commandline -t)
# can't use `for token in tokens[1..-2]` due to
set -e tokens[-1]
for token in $tokens # ignoring current token
if string match -e @ -- $token
return 1
return 0
# scp specific completions
# Inherit user/host completions from ssh
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.*' ':')"
# Local path
complete -c scp -d "Local Path" -n "not string match @ -- (commandline -ct)"
# Remote path
# Get the list of remote files from the scp target.
complete -c scp -d "Remote Path" -f -n "commandline -ct | string match -eq ':'" -a "
(__scp_remote_target):( \
command ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) /bin/ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null
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"
You can’t perform that action at this time.