mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-27 00:00:08 +00:00
fix: Added support for include in config file to ssh plugin
This commit is contained in:
parent
367e9381df
commit
b0c3eb32f5
1 changed files with 45 additions and 9 deletions
|
@ -4,16 +4,52 @@
|
||||||
# Filter out wildcard host sections.
|
# Filter out wildcard host sections.
|
||||||
_ssh_configfile="$HOME/.ssh/config"
|
_ssh_configfile="$HOME/.ssh/config"
|
||||||
if [[ -f "$_ssh_configfile" ]]; then
|
if [[ -f "$_ssh_configfile" ]]; then
|
||||||
_ssh_hosts=($(
|
|
||||||
egrep '^Host.*' "$_ssh_configfile" |\
|
parse_ssh_config() {
|
||||||
awk '{for (i=2; i<=NF; i++) print $i}' |\
|
local config_file="$1"
|
||||||
sort |\
|
|
||||||
uniq |\
|
if [[ -f "$config_file" ]]; then
|
||||||
grep -v '^*' |\
|
# Extract all "Host" entries
|
||||||
sed -e 's/\.*\*$//'
|
local hosts=($(
|
||||||
))
|
egrep -i '^Host.*' "$config_file" |\
|
||||||
zstyle ':completion:*:hosts' hosts $_ssh_hosts
|
awk '{for (i=2; i<=NF; i++) print $i}' |\
|
||||||
|
sort |\
|
||||||
|
uniq |\
|
||||||
|
grep -v '^*' |\
|
||||||
|
sed -e 's/\.*\*$//'
|
||||||
|
))
|
||||||
|
|
||||||
|
# Add hosts to the global array
|
||||||
|
_ssh_hosts+=("${hosts[@]}")
|
||||||
|
|
||||||
|
# Handle Include directives by reading the files they reference
|
||||||
|
local includes=($(egrep '^Include ' "$config_file" | awk '{print $2}'))
|
||||||
|
|
||||||
|
# Loop through each included file or pattern
|
||||||
|
for include in "${includes[@]}"; do
|
||||||
|
|
||||||
|
# Resolve relative paths and handle wildcards
|
||||||
|
for file in $(eval echo $include); do
|
||||||
|
parse_ssh_config "$file"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_ssh_hosts=()
|
||||||
|
# Start parsing from the main SSH config file
|
||||||
|
_ssh_configfile="$HOME/.ssh/config"
|
||||||
|
parse_ssh_config "$_ssh_configfile"
|
||||||
|
_final_hosts=($(sort <<< "${_ssh_hosts[@]}" |\
|
||||||
|
uniq |\
|
||||||
|
grep -v '^*' |\
|
||||||
|
sed -e 's/\.*\*$//'
|
||||||
|
))
|
||||||
|
|
||||||
|
zstyle ':completion:*:hosts' hosts $_final_hosts
|
||||||
unset _ssh_hosts
|
unset _ssh_hosts
|
||||||
|
unset _final_hosts
|
||||||
fi
|
fi
|
||||||
unset _ssh_configfile
|
unset _ssh_configfile
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue