aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-22 17:15:32 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-22 17:15:32 +1200
commit4d2d0d760627dfaa5bff0e197bc827f4214c3211 (patch)
tree7a82edbab181fb8fb5aca99bed39ac8577e0ac4e
parentf38012c243df1e4edcc6c13ba297c13a81633451 (diff)
downloaddotfiles-4d2d0d760627dfaa5bff0e197bc827f4214c3211.tar.gz
Split completions that use ssh_config(5) hosts
-rw-r--r--bash/bash_completion.d/_ssh_config_hosts.bash21
-rw-r--r--bash/bash_completion.d/sftp.bash4
-rw-r--r--bash/bash_completion.d/ssh-copy-id.bash4
-rw-r--r--bash/bash_completion.d/ssh.bash26
4 files changed, 33 insertions, 22 deletions
diff --git a/bash/bash_completion.d/_ssh_config_hosts.bash b/bash/bash_completion.d/_ssh_config_hosts.bash
new file mode 100644
index 00000000..02e9af06
--- /dev/null
+++ b/bash/bash_completion.d/_ssh_config_hosts.bash
@@ -0,0 +1,21 @@
+# Complete ssh_config(5) hostnames
+_ssh_config_hosts() {
+
+ # 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
+}
diff --git a/bash/bash_completion.d/sftp.bash b/bash/bash_completion.d/sftp.bash
new file mode 100644
index 00000000..5d52c739
--- /dev/null
+++ b/bash/bash_completion.d/sftp.bash
@@ -0,0 +1,4 @@
+# Completion for sftp(1) with ssh_config(5) hostnames
+declare -F _ssh_config_hosts >/dev/null ||
+ source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
+complete -F _ssh_config_hosts -o default sftp
diff --git a/bash/bash_completion.d/ssh-copy-id.bash b/bash/bash_completion.d/ssh-copy-id.bash
new file mode 100644
index 00000000..daf52751
--- /dev/null
+++ b/bash/bash_completion.d/ssh-copy-id.bash
@@ -0,0 +1,4 @@
+# Completion for ssh-copy-id(1) with ssh_config(5) hostnames
+declare -F _ssh_config_hosts >/dev/null ||
+ source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
+complete -F _ssh_config_hosts -o default ssh-copy-id
diff --git a/bash/bash_completion.d/ssh.bash b/bash/bash_completion.d/ssh.bash
index bbb9b246..03745eaa 100644
--- a/bash/bash_completion.d/ssh.bash
+++ b/bash/bash_completion.d/ssh.bash
@@ -1,22 +1,4 @@
-# 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
+# Completion for ssh(1) with ssh_config(5) hostnames
+declare -F _ssh_config_hosts >/dev/null ||
+ source "$HOME"/.bash_completion.d/_ssh_config_hosts.bash
+complete -F _ssh_config_hosts -o default ssh