Skip to content

Commit

Permalink
scp: address shellcheck SC2089 and SC2090
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Apr 11, 2020
1 parent 198d3f7 commit c906aeb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ _sftp()
shopt -u hostcomplete && complete -F _sftp sftp

# things we want to backslash escape in scp paths
# shellcheck disable=SC2089
_scp_path_esc='[][(){}<>",:;^&!$=?`|\\'"'"'[:space:]]'

# Complete remote files with ssh. If the first arg is -d, complete on dirs
Expand All @@ -414,6 +415,7 @@ _scp_remote_files()
local path=${cur#*:}

# unescape (3 backslashes to 1 for chars we escaped)
# shellcheck disable=SC2090
path=$(command sed -e 's/\\\\\\\('$_scp_path_esc'\)/\\\1/g' <<<"$path")

# default to home dir of specified user on remote host
Expand All @@ -424,12 +426,14 @@ _scp_remote_files()
local files
if [[ $1 == -d ]]; then
# escape problematic characters; remove non-dirs
# shellcheck disable=SC2090
files=$(ssh -o 'Batchmode yes' $userhost \
command ls -aF1dL "$path*" 2>/dev/null | \
command sed -e 's/'$_scp_path_esc'/\\\\\\&/g' -e '/[^\/]$/d')
else
# escape problematic characters; remove executables, aliases, pipes
# and sockets; add space at end of file names
# shellcheck disable=SC2090
files=$(ssh -o 'Batchmode yes' $userhost \
command ls -aF1dL "$path*" 2>/dev/null | \
command sed -e 's/'$_scp_path_esc'/\\\\\\&/g' -e 's/[*@|=]$//g' \
Expand Down

0 comments on commit c906aeb

Please sign in to comment.