1
- #! /usr/bin/env bash
1
+ # shellcheck shell= bash
2
2
# Bash completion support for ssh.
3
3
4
4
export COMP_WORDBREAKS=${COMP_WORDBREAKS/ \: / }
5
5
6
6
_sshcomplete () {
7
- local CURRENT_PROMPT=" ${COMP_WORDS[COMP_CWORD]} "
7
+ local line CURRENT_PROMPT=" ${COMP_WORDS[COMP_CWORD]} "
8
8
if [[ ${CURRENT_PROMPT} == * @* ]]; then
9
9
local OPTIONS=" -P ${CURRENT_PROMPT/@*/ } @ -- ${CURRENT_PROMPT/*@/ } "
10
10
else
@@ -17,20 +17,21 @@ _sshcomplete() {
17
17
| awk ' {for (i=2; i<=NF; i++) print $i}' \
18
18
| sed -Ee " s|^([^/~])|$HOME /.ssh/\1|" -e " s|^~/|$HOME /|" ) ; do
19
19
if [ -r " $fl " ]; then
20
- COMPREPLY=(${COMPREPLY[@]} $( compgen -W " $( grep -i ^Host " $fl " | grep -v ' [*!]' | awk ' {for (i=2; i<=NF; i++) print $i}' ) " ${OPTIONS} ) )
20
+ # shellcheck disable=SC2086
21
+ while IFS=' ' read -r line; do COMPREPLY+=(" $line " ); done < <( compgen -W " $( grep -i ^Host " $fl " | grep -v ' [*!]' | awk ' {for (i=2; i<=NF; i++) print $i}' ) " ${OPTIONS} )
21
22
fi
22
23
done
23
24
24
25
# parse all hosts found in .ssh/known_hosts
25
- if [ -r " $HOME /.ssh/known_hosts" ]; then
26
- if grep -v -q -e ' ^ ssh-rsa' " $HOME /.ssh/known_hosts" ; then
27
- COMPREPLY=(${COMPREPLY[@]} $( compgen -W " $( awk ' {print $1}' " $HOME /.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e ' s/\[//g' | sed -e ' s/\]//g' | cut -d: -f1 | grep -v ssh-rsa) " ${OPTIONS} ) )
28
- fi
26
+ if [ -r " $HOME /.ssh/known_hosts" ] && grep -v -q -e ' ^ ssh-rsa' " $HOME /.ssh/known_hosts" ; then
27
+ # shellcheck disable=SC2086
28
+ while IFS=' ' read -r line; do COMPREPLY+=(" $line " ); done < <( compgen -W " $( awk ' {print $1}' " $HOME /.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e ' s/\[//g' | sed -e ' s/\]//g' | cut -d: -f1 | grep -v ssh-rsa) " ${OPTIONS} )
29
29
fi
30
30
31
31
# parse hosts defined in /etc/hosts
32
32
if [ -r /etc/hosts ]; then
33
- COMPREPLY=(${COMPREPLY[@]} $( compgen -W " $( grep -v ' ^[[:space:]]*$' /etc/hosts | grep -v ' ^#' | awk ' {for (i=2; i<=NF; i++) print $i}' ) " ${OPTIONS} ) )
33
+ # shellcheck disable=SC2086
34
+ while IFS=' ' read -r line; do COMPREPLY+=(" $line " ); done < <( compgen -W " $( grep -v ' ^[[:space:]]*$' /etc/hosts | grep -v ' ^#' | awk ' {for (i=2; i<=NF; i++) print $i}' ) " ${OPTIONS} )
34
35
fi
35
36
36
37
return 0
0 commit comments