Skip to content

Commit

Permalink
Fix remote path escaping for rsync and scp completions
Browse files Browse the repository at this point in the history
They need to be escaped twice, for the local and the remote shell.
Also don't suggest local files as rsync remote paths (-a -> -xa) and
fix completion for remote paths containing multiple consecutive spaces.

Fixes #1872
[ci skip]
  • Loading branch information
krobelus committed Jan 13, 2020
1 parent e378260 commit 0c92c7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions share/completions/rsync.fish
@@ -1,5 +1,5 @@
function __rsync_remote_target
commandline -ct | string match -r '.*::?(?:.*/)?'
commandline -ct | string match -r '.*::?(?:.*/)?' | string unescape
end

complete -c rsync -s v -l verbose -d "Increase verbosity"
Expand Down Expand Up @@ -125,12 +125,14 @@ complete -c rsync -d Hostname -a "
#
# Remote path
#
complete -c rsync -d "Remote path" -n "commandline -ct | string match -q '*:*'" -a "
complete -c rsync -d "Remote path" -n "commandline -ct | string match -q '*:*'" -xa "
(
# Prepend any user@host:/path information supplied before the remote completion.
__rsync_remote_target
)(
# Get the list of remote files from the specified rsync server.
rsync --list-only (__rsync_remote_target) 2>/dev/null | string replace -r '^d.*' '\$0/' | tr -s ' ' | cut -d' ' -f 5-
rsync --list-only (__rsync_remote_target) 2>/dev/null | string replace -r '^d.*' '\$0/' |
string replace -r '(\S+\s+){4}' '' | # drop the first four columns
string escape -n
)
"
3 changes: 2 additions & 1 deletion share/completions/scp.fish
Expand Up @@ -54,7 +54,8 @@ complete -c scp -d "Local Path" -n "not string match @ -- (commandline -ct)"
# Get the list of remote files from the scp target.
complete -c scp -d "Remote Path" -f -n "commandline -ct | string match -e ':'" -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
command ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) /bin/ls\ -dp\ (__scp_remote_path_prefix | string unescape)\* 2>/dev/null |
string escape -n
)
"
complete -c scp -s B -d "Batch mode"
Expand Down

0 comments on commit 0c92c7d

Please sign in to comment.