Created
February 7, 2023 20:13
-
-
Save rawiriblundell/4a978b7e715fd4444254780998fb648a to your computer and use it in GitHub Desktop.
Standard scp autocompletion was breaking on my ssh config structure. This fixes that by focusing on known_hosts only. If it's in the configs, then it should be in known_hosts, right?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__complete_ssh_host() { | |
local ssh_known_file ssh_known_list partial_word | |
ssh_known_file="${HOME}/.ssh/known_hosts" | |
[[ -r "${ssh_known_file}" ]] || return 1 | |
ssh_known_list=$(awk '{print $1}' "${HOME}"/.ssh/known_hosts | tr ',' '\n' | sort | uniq) | |
partial_word="${COMP_WORDS[COMP_CWORD]}"; | |
mapfile -t COMPREPLY < <(compgen -W "${ssh_known_list}" -- "${partial_word}") | |
return 0 | |
} | |
complete -F __complete_ssh_host ssh | |
complete -f -F __complete_ssh_host scp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment