fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Kristof Matteifix: invoke the `rm` command, bypassing custom rm functions which might block3237efc58

master
3.1 KiB79 linesraw
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.
9    set -l port (commandline -c | string match -r -- ' -P ?(\d+)\b')
10    and echo $port[2]
11end
12
13function __scp_remote_target
14    set -l target (commandline -ct | string match -r -- '(.*):')
15    and echo $target[2]
16end
17
18function __scp_remote_path_prefix
19    set -l path_prefix (commandline -ct | string match -r -- ':(.*)')
20    and echo $path_prefix[2]
21end
22
23function __fish_no_scp_remote_specified
24    set -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
26    set -e tokens[-1]
27    for token in $tokens # ignoring current token
28        if string match -e @ -- $token
29            return 1
30        end
31    end
32    return 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):(
49        if not set -q __fish_scp_sftp
50            if set -l tmp (__fish_mktemp_relative fish-scp)
51                and scp -P(__scp2ssh_port_number) -o "BatchMode yes" -q -O $tmp (__scp_remote_target):/dev/null
52                set -g __fish_scp_sftp true
53            else
54                set -g __fish_scp_sftp false
55            end
56            if set -q tmp[1]
57                command rm $tmp
58            end
59        end
60        if $__fish_scp_sftp
61            command ssh -p(__scp2ssh_port_number) -o "BatchMode yes" (__scp_remote_target) command\ ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null
62        else
63            command ssh -p(__scp2ssh_port_number) -o "BatchMode yes" (__scp_remote_target) command\ ls\ -dp\ (__scp_remote_path_prefix | string unescape)\* 2>/dev/null |
64            string escape -n
65        end
66    )
67'
68
69complete -c scp -s 3 -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"