aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/ssh.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bash_completion.d/ssh.bash')
-rw-r--r--bash/bash_completion.d/ssh.bash22
1 files changed, 22 insertions, 0 deletions
diff --git a/bash/bash_completion.d/ssh.bash b/bash/bash_completion.d/ssh.bash
new file mode 100644
index 00000000..bbb9b246
--- /dev/null
+++ b/bash/bash_completion.d/ssh.bash
@@ -0,0 +1,22 @@
+# Completion for ssh/sftp/ssh-copy-id with config hostnames
+_ssh() {
+
+ # Read hostnames from existent config files, no asterisks
+ local -a hosts
+ local config option value
+ for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
+ [[ -e $config ]] || continue
+ while read -r option value _ ; do
+ [[ $option == Host ]] || continue
+ [[ $value != *'*'* ]] || continue
+ hosts[${#hosts[@]}]=$value
+ done < "$config"
+ done
+
+ # Generate completion reply
+ for host in "${hosts[@]}" ; do
+ [[ $host == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
+ COMPREPLY[${#COMPREPLY[@]}]=$host
+ done
+}
+complete -F _ssh -o default ssh sftp ssh-copy-id