ssh-completion.sh 383 B

123456789101112131415
  1. # https://unix.stackexchange.com/questions/50054/bash-auto-completion-feature-for-sshing-into-different-hosts
  2. _ssh()
  3. {
  4. local cur prev opts
  5. COMPREPLY=()
  6. cur="${COMP_WORDS[COMP_CWORD]}"
  7. prev="${COMP_WORDS[COMP_CWORD-1]}"
  8. opts=$(grep '^Host' ~/.ssh/config | awk '{print $2}')
  9. COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
  10. return 0
  11. }
  12. complete -F _ssh ssh