fix(completions/ssh): detect Include option in ~/.ssh/config and parse content files for completion

This commit is contained in:
me
2024-02-22 09:37:02 +01:00
committed by Koichi Murase
parent b63339088f
commit 084a3026b1

View File

@ -5,7 +5,7 @@ _omb_module_require lib:omb-completion
function _omb_completion_ssh { function _omb_completion_ssh {
local cur local cur
local file_in_config_d local additional_include_defined_file
_omb_completion_reassemble_breaks : _omb_completion_reassemble_breaks :
if [[ $cur == *@* ]] ; then if [[ $cur == *@* ]] ; then
@ -19,12 +19,11 @@ function _omb_completion_ssh {
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}")) COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}"))
fi fi
# parse all defined hosts from .ssh/config.d/* # check if .ssh/config contains Include options
if [[ -d $HOME/.ssh/config.d ]]; then for additional_include_defined_file in $(awk -F' ' '/^Înclude/{print $2}' 2>/dev/null) ;do
for file_in_config_d in "$HOME/.ssh/config.d/"* ;do # parse all defined hosts from that file
[[ -s "$file_in_config_d" ]] &&COMPREPLY+=($(compgen -W "$(grep ^Host "$file_in_config_d" | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}")) [[ -s "$additional_include_defined_file" ]] &&COMPREPLY+=($(compgen -W "$(grep ^Host "$additional_include_defined_file" | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}"))
done done
fi
# parse all hosts found in .ssh/known_hosts # parse all hosts found in .ssh/known_hosts
if [[ -r $HOME/.ssh/known_hosts ]]; then if [[ -r $HOME/.ssh/known_hosts ]]; then