diff options
| author | Koichi Murase <myoga.murase@gmail.com> | 2025-06-04 14:50:40 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-06-05 13:02:11 +0900 |
| commit | e3f4a51c189acbfe2235b7f35bbb4685d8632c03 (patch) | |
| tree | 75aa8556aaf3f573fbef053140346892b908c2a9 /shell | |
| parent | 0a06fd6f633fdf07ec04b2a9e92a266207240fb8 (diff) | |
| download | fzf-e3f4a51c189acbfe2235b7f35bbb4685d8632c03.tar.gz | |
[zsh] Set shell options for pathname expansion "~/.ssh/config.d/*"
This applies the same changes as commit 0a06fd6f for Bash (GitHub PR
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/completion.zsh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/shell/completion.zsh b/shell/completion.zsh index 2d06ff50..49f7ee43 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -242,8 +242,19 @@ _fzf_complete() { # desired sorting and with any duplicates removed, to standard output. if ! declare -f __fzf_list_hosts > /dev/null; then __fzf_list_hosts() { - setopt localoptions nonomatch - command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \ + command cat \ + <( + # Note: To make the pathname expansion of "~/.ssh/config.d/*" work + # properly, we need to adjust the related shell options. We need to + # unset "NO_GLOB" (or reset "GLOB"), which disable the pathname + # expansion totally. We need to unset "DOT_GLOB" and set "CASE_GLOB" + # to avoid matching unwanted files. We need to set "NULL_GLOB" to + # avoid attempting to read the literal filename '~/.ssh/config.d/*' + # when no matching is found. + setopt GLOB NO_DOT_GLOB CASE_GLOB NO_NOMATCH NULL_GLOB + + command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]' + ) \ <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \ <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') | awk '{for (i = 2; i <= NF; i++) print $i}' | sort -u |
