mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-04 06:02:04 -07:00
[bash,zsh] Reduce the number of fork & exec
This commit is contained in:
committed by
Junegunn Choi
parent
e3f4a51c18
commit
ec521e47aa
@@ -460,7 +460,7 @@ _fzf_proc_completion_post() {
|
|||||||
# }
|
# }
|
||||||
if ! declare -F __fzf_list_hosts > /dev/null; then
|
if ! declare -F __fzf_list_hosts > /dev/null; then
|
||||||
__fzf_list_hosts() {
|
__fzf_list_hosts() {
|
||||||
command cat \
|
command sort -u \
|
||||||
<(
|
<(
|
||||||
# Note: To make the pathname expansion of "~/.ssh/config.d/*" work
|
# Note: To make the pathname expansion of "~/.ssh/config.d/*" work
|
||||||
# properly, we need to adjust the related shell options. We need to
|
# properly, we need to adjust the related shell options. We need to
|
||||||
@@ -475,11 +475,34 @@ if ! declare -F __fzf_list_hosts > /dev/null; then
|
|||||||
shopt -u dotglob nocaseglob failglob
|
shopt -u dotglob nocaseglob failglob
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
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 '[*?%]'
|
command awk '
|
||||||
|
tolower($1) ~ /^host(name)?$/ {
|
||||||
|
for (i = 2; i <= NF; i++)
|
||||||
|
if ($i !~ /[*?%]/)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null
|
||||||
) \
|
) \
|
||||||
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \
|
<(
|
||||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |
|
command awk -F ',' '
|
||||||
command awk '{for (i = 2; i <= NF; i++) print $i}' | command sort -u
|
match($0, /^[[a-z0-9.,:-]+/) {
|
||||||
|
$0 = substr($0, 1, RLENGTH)
|
||||||
|
gsub(/\[/, "")
|
||||||
|
for (i = 1; i <= NF; i++)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' ~/.ssh/known_hosts 2> /dev/null
|
||||||
|
) \
|
||||||
|
<(
|
||||||
|
command awk '
|
||||||
|
/^[[:blank:]]*(#|$)|0\.0\.0\.0/ { next }
|
||||||
|
{
|
||||||
|
sub(/#.*/, "")
|
||||||
|
for (i = 2; i <= NF; i++)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' /etc/hosts 2> /dev/null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -242,7 +242,7 @@ _fzf_complete() {
|
|||||||
# desired sorting and with any duplicates removed, to standard output.
|
# desired sorting and with any duplicates removed, to standard output.
|
||||||
if ! declare -f __fzf_list_hosts > /dev/null; then
|
if ! declare -f __fzf_list_hosts > /dev/null; then
|
||||||
__fzf_list_hosts() {
|
__fzf_list_hosts() {
|
||||||
command cat \
|
command sort -u \
|
||||||
<(
|
<(
|
||||||
# Note: To make the pathname expansion of "~/.ssh/config.d/*" work
|
# Note: To make the pathname expansion of "~/.ssh/config.d/*" work
|
||||||
# properly, we need to adjust the related shell options. We need to
|
# properly, we need to adjust the related shell options. We need to
|
||||||
@@ -253,11 +253,34 @@ if ! declare -f __fzf_list_hosts > /dev/null; then
|
|||||||
# when no matching is found.
|
# when no matching is found.
|
||||||
setopt GLOB NO_DOT_GLOB CASE_GLOB NO_NOMATCH NULL_GLOB
|
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 awk '
|
||||||
|
tolower($1) ~ /^host(name)?$/ {
|
||||||
|
for (i = 2; i <= NF; i++)
|
||||||
|
if ($i !~ /[*?%]/)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null
|
||||||
) \
|
) \
|
||||||
<(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/#.*//') |
|
command awk -F ',' '
|
||||||
awk '{for (i = 2; i <= NF; i++) print $i}' | sort -u
|
match($0, /^[[a-z0-9.,:-]+/) {
|
||||||
|
$0 = substr($0, 1, RLENGTH)
|
||||||
|
gsub(/\[/, "")
|
||||||
|
for (i = 1; i <= NF; i++)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' ~/.ssh/known_hosts 2> /dev/null
|
||||||
|
) \
|
||||||
|
<(
|
||||||
|
command awk '
|
||||||
|
/^[[:blank:]]*(#|$)|0\.0\.0\.0/ { next }
|
||||||
|
{
|
||||||
|
sub(/#.*/, "")
|
||||||
|
for (i = 2; i <= NF; i++)
|
||||||
|
print $i
|
||||||
|
}
|
||||||
|
' /etc/hosts 2> /dev/null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user