Skip to content

Commit 180aa9d

Browse files
committed
bring to compliance: ssh.completion
1 parent 0a34ad1 commit 180aa9d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

completion/available/ssh.completion.bash

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22
# Bash completion support for ssh.
33

44
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
55

66
_sshcomplete() {
7-
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
7+
local line CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}"
88
if [[ ${CURRENT_PROMPT} == *@* ]]; then
99
local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}"
1010
else
@@ -17,20 +17,21 @@ _sshcomplete() {
1717
| awk '{for (i=2; i<=NF; i++) print $i}' \
1818
| sed -Ee "s|^([^/~])|$HOME/.ssh/\1|" -e "s|^~/|$HOME/|"); do
1919
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})
2122
fi
2223
done
2324

2425
# 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})
2929
fi
3030

3131
# parse hosts defined in /etc/hosts
3232
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})
3435
fi
3536

3637
return 0

0 commit comments

Comments
 (0)