mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Fix scp completions to support bidirectional transfer
Also hardcode standard /bin/ls to avoid issues with `ls` aliases on the target, and inherit the (improved) list of remotes from `ssh`.
This commit is contained in:
parent
c8c3265cb8
commit
086d088e1b
3 changed files with 22 additions and 10 deletions
|
@ -81,6 +81,7 @@ This section is for changes merged to the `major` branch that are not also merge
|
||||||
- `npm`<sup>†</sup>
|
- `npm`<sup>†</sup>
|
||||||
- `python`/`python2`/`python3`
|
- `python`/`python2`/`python3`
|
||||||
- `service`
|
- `service`
|
||||||
|
- `scp`
|
||||||
- `ssh` (#4344)
|
- `ssh` (#4344)
|
||||||
- `sudo` (see above)
|
- `sudo` (see above)
|
||||||
- `yarn`<sup>∗</sup><sup>†</sup>
|
- `yarn`<sup>∗</sup><sup>†</sup>
|
||||||
|
|
|
@ -22,28 +22,39 @@ function __scp_remote_path_prefix
|
||||||
and echo $path_prefix[2]
|
and echo $path_prefix[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function __fish_no_scp_remote_specified
|
||||||
|
set -l tokens (commandline -t)
|
||||||
|
# can't use `for token in tokens[1..-2]` due to https://github.com/fish-shell/fish-shell/issues/4897
|
||||||
|
set -e tokens[-1]
|
||||||
|
for token in $tokens # ignoring current token
|
||||||
|
if string match -e @ -- $token
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# scp specific completions
|
# scp specific completions
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# Hostname
|
# Inherit user/host completions from ssh
|
||||||
#
|
#
|
||||||
complete -c scp -d Hostname -n "commandline --cut-at-cursor --current-token | string match -v '*:*'" -a "
|
complete -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.*' ':')"
|
||||||
(__fish_complete_user_at_hosts):"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Local path
|
# Local path
|
||||||
#
|
#
|
||||||
complete -c scp -d "Local Path" -n "commandline -ct | string match ':'"
|
complete -c scp -d "Local Path" -n "not string match @ -- (commandline -ct)"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Remote path
|
# Remote path
|
||||||
#
|
#
|
||||||
complete -c scp -d "Remote Path" -f -n "commandline --cut-at-cursor --current-token | string match -r '.+:'" -a "
|
# Get the list of remote files from the scp target.
|
||||||
(__scp_remote_target):(
|
complete -c scp -d "Remote Path" -f -n "commandline -ct | string match -eq ':'" -a "
|
||||||
# Get the list of remote files from the scp target.
|
(__scp_remote_target):( \
|
||||||
ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null
|
ssh (__scp2ssh_port_number) -o 'BatchMode yes' (__scp_remote_target) /bin/ls\ -dp\ (__scp_remote_path_prefix)\* 2>/dev/null
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
complete -c scp -s B -d "Batch mode"
|
complete -c scp -s B -d "Batch mode"
|
||||||
|
|
|
@ -6,7 +6,7 @@ __fish_complete_ssh ssh
|
||||||
#
|
#
|
||||||
# ssh specific completions
|
# ssh specific completions
|
||||||
#
|
#
|
||||||
complete -x -c ssh -d Hostname -a "(__fish_complete_user_at_hosts)"
|
complete -x -c ssh -d "Remote" -a "(__fish_complete_user_at_hosts)"
|
||||||
|
|
||||||
# Disable as username completion is not very useful.
|
# Disable as username completion is not very useful.
|
||||||
# complete -x -c ssh -d User -a "
|
# complete -x -c ssh -d User -a "
|
||||||
|
@ -51,4 +51,4 @@ function __ssh_history_completions --argument limit
|
||||||
history --prefix ssh | sed -n "s/.* \([A-Za-z0-9._:-]\+@[A-Za-z0-9._:-]\+\).*/\1/p" | head -n $limit
|
history --prefix ssh | sed -n "s/.* \([A-Za-z0-9._:-]\+@[A-Za-z0-9._:-]\+\).*/\1/p" | head -n $limit
|
||||||
end
|
end
|
||||||
|
|
||||||
complete -k -c ssh -a '(__ssh_history_completions 100)' -f
|
complete -k -c ssh -a '(__ssh_history_completions 100)' -f -d "Remote"
|
||||||
|
|
Loading…
Reference in a new issue