Improve completions for ssh by completing from history

This commit is contained in:
Mahmoud Al-Qudsi 2018-04-12 21:40:10 -05:00
parent 14d59c53f6
commit facdc88c0c
2 changed files with 12 additions and 0 deletions

View file

@ -69,6 +69,7 @@ This section is for changes merged to the `major` branch that are not also merge
- `brew`
- `diskutil`
- `yarn`
- `ssh` (#4344)
--

View file

@ -41,3 +41,14 @@ complete -c ssh -s X -d "Enable X11 forwarding"
complete -c ssh -s L -d "Locally forwarded ports"
complete -c ssh -s R -d "Remotely forwarded ports"
complete -c ssh -s D -d "Dynamic port forwarding"
# Also look up hosts from the history
function __ssh_history_completions --argument limit
if string match -q ""
set limit 100
end
history --prefix ssh | sed -n "s/.* \([A-Za-z0-9._:-]\+@[A-Za-z0-9._:-]\+\).*/\1/p" | head -n $limit
end
complete -k -c ssh -a '(__ssh_history_completions 100)' -f