fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
3237efc58
master
1# Load completions shared by various ssh tools like ssh, scp and sftp. 2__fish_complete_ssh scp 3 4# Helper functions to simplify the completions. 5function __scp2ssh_port_number 6# There is a silly inconsistency between the ssh and scp commands regarding the short flag name 7# for specifying the TCP port number. This function deals with that by extracting the port 8# number if present. 9set -l port( commandline -c| string match -r --' -P ?(\d+)\b' ) 10and echo $port [ 2 ] 11end 12 13function __scp_remote_target 14set -l target( commandline -ct| string match -r --'(.*):' ) 15and echo $target [ 2 ] 16end 17 18function __scp_remote_path_prefix 19set -l path_prefix( commandline -ct| string match -r --':(.*)' ) 20and echo $path_prefix [ 2 ] 21end 22 23function __fish_no_scp_remote_specified 24set -l tokens( commandline -t) 25# can't use `for token in tokens[1..-2]` due to https://github.com/fish-shell/fish-shell/issues/4897 26set -e tokens[ -1 ] 27for tokenin $tokens # ignoring current token 28if string match -e @ --$token 29return 1 30end 31end 32return 0 33end 34 35# 36# scp specific completions 37# 38 39# Inherit user/host completions from ssh 40complete -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.*' ':')" 41 42# Local path 43complete -c scp -d"Local Path" -n"not string match @ -- (commandline -ct)" 44 45# Remote path 46# Get the list of remote files from the scp target. 47complete -c scp -d"Remote Path" -f -n"commandline -ct | string match -e ':'" -a' 48(__scp_remote_target):( 49if not set -q __fish_scp_sftp 50if set -l tmp (__fish_mktemp_relative fish-scp) 51and scp -P(__scp2ssh_port_number) -o "BatchMode yes" -q -O $tmp (__scp_remote_target):/dev/null 52set -g __fish_scp_sftp true 53else 54set -g __fish_scp_sftp false 55end 56if set -q tmp[1] 57command rm $tmp 58end 59end 60if $__fish_scp_sftp 61command ssh -p(__scp2ssh_port_number) -o "BatchMode yes" (__scp_remote_target) command\ ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null 62else 63command ssh -p(__scp2ssh_port_number) -o "BatchMode yes" (__scp_remote_target) command\ ls\ -dp\ (__scp_remote_path_prefix | string unescape)\* 2>/dev/null | 64string escape -n 65end 66) 67' 68 69complete -c scp -s3 -d"Copies between two remote hosts are transferred through the local host" 70complete -c scp -s B -d"Batch mode" 71complete -c scp -s D -x -d"Connect directly to a local SFTP server" 72complete -c scp -s l -x -d"Bandwidth limit" 73complete -c scp -s O -d"Use original SCP protocol instead of SFTP" 74complete -c scp -s P -x -d Port 75complete -c scp -s p -d"Preserves modification times, access times, and modes from the original file" 76complete -c scp -s R -d"Copies between two remote hosts are performed by executing scp on the origin host" 77complete -c scp -s r -d"Recursively copy" 78complete -c scp -s S -d"Encryption program" 79complete -c scp -s T -d"Disable strict filename checking"