From cc3efcc3ab64f7206d1863786623703d71063887 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 14 Apr 2017 23:21:17 -0700 Subject: [PATCH] a step to remove __fish_sgrep per issue #2450 --- __fish_not_contain_opt.err | 0 share/completions/scp.fish | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 __fish_not_contain_opt.err diff --git a/__fish_not_contain_opt.err b/__fish_not_contain_opt.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/share/completions/scp.fish b/share/completions/scp.fish index 528cdcec3..f6c959198 100644 --- a/share/completions/scp.fish +++ b/share/completions/scp.fish @@ -3,6 +3,25 @@ # __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] +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 + # # scp specific completions # @@ -11,7 +30,6 @@ __fish_complete_ssh scp # Hostname # complete -c scp -d Hostname -n "commandline --cut-at-cursor --current-token | string match -v '*:*'" -a " - (__fish_print_hostnames): ( @@ -29,15 +47,10 @@ complete -c scp -d "Local Path" -n "commandline -ct | string match ':'" # Remote path # complete -c scp -d "Remote Path" -f -n "commandline --cut-at-cursor --current-token | string match -r '.+:'" -a " - -( - #Prepend any user@host information supplied before the remote completion - commandline -ct| __fish_sgrep -o '.*:' -)( - #Get the list of remote files from the specified ssh server - ssh (commandline -c| __fish_sgrep -o '\-P [0-9]*'|tr P p) -o \"BatchMode yes\" (commandline -ct|sed -ne 's/\(.*\):.*/\1/p') ls\ -dp\ (commandline -ct|sed -ne 's/.*://p')\* 2> /dev/null +(__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 ) - " complete -c scp -s B -d "Batch mode" complete -c scp -s l -x -d "Bandwidth limit"