Skip to content
Myr

[bash,zsh] Reduce the number of fork & exec

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Koichi Murase · committed by Junegunn Choi · parent e3f4a51 · Browse files · 2 files+56 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+56 added−10 removed

  • other:+56 added−10 removed

2 files+56 added−10 removed

modified:shell/completion.bash+28 added-5 removed
458 unmodified lines
459# printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort460# }461if ! declare -F __fzf_list_hosts > /dev/null; then462 __fzf_list_hosts() {463 command cat \463 command sort -u \464 <(465 # Note: To make the pathname expansion of "~/.ssh/config.d/*" work466 # properly, we need to adjust the related shell options. We need to467 # unset "set -f" and "GLOBIGNORE", which disable the pathname expansion
6 unmodified lines
474 GLOBIGNORE=475 shopt -u dotglob nocaseglob failglob476 shopt -s nullglob477478 command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]'478 command awk '479 tolower($1) ~ /^host(name)?$/ {480 for (i = 2; i <= NF; i++)481 if ($i !~ /[*?%]/)482 print $i483 }484 ' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null485 ) \480 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \481 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |482 command awk '{for (i = 2; i <= NF; i++) print $i}' | command sort -u486 <(487 command awk -F ',' '488 match($0, /^[[a-z0-9.,:-]+/) {489 $0 = substr($0, 1, RLENGTH)490 gsub(/\[/, "")491 for (i = 1; i <= NF; i++)492 print $i493 }494 ' ~/.ssh/known_hosts 2> /dev/null495 ) \496 <(497 command awk '498 /^[[:blank:]]*(#|$)|0\.0\.0\.0/ { next }499 {500 sub(/#.*/, "")501 for (i = 2; i <= NF; i++)502 print $i503 }504 ' /etc/hosts 2> /dev/null 505 )506 }507fi508509_fzf_host_completion() {
155 unmodified lines
modified:shell/completion.zsh+28 added-5 removed
240 unmodified lines
241# The function is expected to print hostnames, one per line as well as in the242# desired sorting and with any duplicates removed, to standard output.243if ! declare -f __fzf_list_hosts > /dev/null; then244 __fzf_list_hosts() {245 command cat \245 command sort -u \246 <(247 # Note: To make the pathname expansion of "~/.ssh/config.d/*" work248 # properly, we need to adjust the related shell options. We need to249 # unset "NO_GLOB" (or reset "GLOB"), which disable the pathname
2 unmodified lines
252 # avoid attempting to read the literal filename '~/.ssh/config.d/*'253 # when no matching is found.254 setopt GLOB NO_DOT_GLOB CASE_GLOB NO_NOMATCH NULL_GLOB255256 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 '[*?%]'256 command awk '257 tolower($1) ~ /^host(name)?$/ {258 for (i = 2; i <= NF; i++)259 if ($i !~ /[*?%]/)260 print $i261 }262 ' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null263 ) \258 <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \259 <(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |260 awk '{for (i = 2; i <= NF; i++) print $i}' | sort -u264 <(265 command awk -F ',' '266 match($0, /^[[a-z0-9.,:-]+/) {267 $0 = substr($0, 1, RLENGTH)268 gsub(/\[/, "")269 for (i = 1; i <= NF; i++)270 print $i271 }272 ' ~/.ssh/known_hosts 2> /dev/null273 ) \274 <(275 command awk '276 /^[[:blank:]]*(#|$)|0\.0\.0\.0/ { next }277 {278 sub(/#.*/, "")279 for (i = 2; i <= NF; i++)280 print $i281 }282 ' /etc/hosts 2> /dev/null283 )284 }285fi286287_fzf_complete_telnet() {
162 unmodified lines