blob: 0c1eb3790ff9992b24854e8bf3ae959e8c44ec31 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# Complete ssh_config(5) hostnames
_ssh_config_hosts() {
# Don't complete anything that wouldn't be in a valid hostname
case $2 in
*[!a-zA-Z0-9.-]*) return 1 ;;
esac
# Iterate through words from a subshell
while read -r word ; do
[[ -n $word ]] || continue
COMPREPLY[${#COMPREPLY[@]}]=$word
done < <(
# Check bind settings to see if we should match case insensitively
while read -r _ setting ; do
case $setting in
('completion-ignore-case on')
shopt -s nocasematch 2>/dev/null
break
;;
esac
done < <(bind -v)
# Iterate through SSH client config paths
for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
[[ -e $config ]] || continue
# Read Host options and their first value from file
while read -r option value _ ; do
[[ $option == Host ]] || continue
# Check host value
case $value in
# Don't complete with wildcard characters
(*'*'*) ;;
# Found a match; print it
("$2"*)
printf '%s\n' "$value"
;;
esac
done < "$config"
done
)
}
|