Skip to content

Commit a61192b

Browse files
committed
refactor: rename { => _comp_compgen}_known_hosts{_real => }
1 parent 45b5cd2 commit a61192b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+165
-158
lines changed

bash_completion

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ _user_at_host()
22832283
_comp_initialize -n : -- "$@" || return
22842284

22852285
if [[ $cur == *@* ]]; then
2286-
_known_hosts_real "$cur"
2286+
_comp_compgen_known_hosts "$cur"
22872287
else
22882288
_comp_compgen -- -u -S @
22892289
compopt -o nospace
@@ -2292,20 +2292,21 @@ _user_at_host()
22922292
shopt -u hostcomplete && complete -F _user_at_host talk ytalk finger
22932293

22942294
# NOTE: Using this function as a helper function is deprecated. Use
2295-
# `_known_hosts_real' instead.
2295+
# `_comp_compgen_known_hosts' instead.
22962296
# TODO:API: rename per conventions
22972297
_known_hosts()
22982298
{
22992299
local cur prev words cword comp_args
23002300
_comp_initialize -n : -- "$@" || return
23012301

2302-
# NOTE: Using `_known_hosts' as a helper function and passing options
2303-
# to `_known_hosts' is deprecated: Use `_known_hosts_real' instead.
2302+
# NOTE: Using `_known_hosts' as a helper function and passing options to
2303+
# `_known_hosts' is deprecated: Use `_comp_compgen_known_hosts'
2304+
# instead.
23042305
local -a options=()
23052306
[[ ${1-} == -a || ${2-} == -a ]] && options+=(-a)
23062307
[[ ${1-} == -c || ${2-} == -c ]] && options+=(-c)
23072308
local IFS=$' \t\n' # Workaround for connected ${v+"$@"} in bash < 4.4
2308-
_known_hosts_real ${options[@]+"${options[@]}"} -- "$cur"
2309+
_comp_compgen_known_hosts ${options[@]+"${options[@]}"} -- "$cur"
23092310
} # _known_hosts()
23102311

23112312
# Helper function to locate ssh included files in configs
@@ -2369,7 +2370,7 @@ _included_ssh_config_files()
23692370
# BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value.
23702371
# Also hosts from HOSTFILE (compgen -A hostname) are added, unless
23712372
# BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
2372-
# Usage: _known_hosts_real [OPTIONS] CWORD
2373+
# Usage: _comp_compgen_known_hosts [OPTIONS] CWORD
23732374
# Options:
23742375
# -a Use aliases from ssh config files
23752376
# -c Use `:' suffix
@@ -2378,9 +2379,17 @@ _included_ssh_config_files()
23782379
# -4 Filter IPv6 addresses from results
23792380
# -6 Filter IPv4 addresses from results
23802381
# @return Completions, starting with CWORD, are added to COMPREPLY[]
2381-
# TODO:API: rename per conventions
2382-
_known_hosts_real()
2382+
# @since 2.12
2383+
_comp_compgen_known_hosts()
2384+
{
2385+
local known_hosts
2386+
_comp_compgen_known_hosts__impl "$@" || return "$?"
2387+
_comp_compgen -U known_hosts set "${known_hosts[@]}"
2388+
}
2389+
_comp_compgen_known_hosts__impl()
23832390
{
2391+
known_hosts=()
2392+
23842393
local configfile="" flag prefix=""
23852394
local cur suffix="" aliases="" i host ipv4="" ipv6=""
23862395
local -a kh tmpkh=() khd=() config=()
@@ -2483,8 +2492,6 @@ _known_hosts_real()
24832492

24842493
# If we have known_hosts files to use
24852494
if ((${#kh[@]} + ${#khd[@]} > 0)); then
2486-
local -a tmp=()
2487-
24882495
if ((${#kh[@]} > 0)); then
24892496
# https://man.openbsd.org/sshd.8#SSH_KNOWN_HOSTS_FILE_FORMAT
24902497
for i in "${kh[@]}"; do
@@ -2506,7 +2513,7 @@ _known_hosts_real()
25062513
# Remove trailing ] + optional :port
25072514
host=${host%]?(:+([0-9]))}
25082515
# Add host to candidates
2509-
[[ $host ]] && tmp+=("$host")
2516+
[[ $host ]] && known_hosts+=("$host")
25102517
done
25112518
fi
25122519
done <"$i"
@@ -2521,21 +2528,21 @@ _known_hosts_real()
25212528
if [[ $i == *key_22_*.pub && -r $i ]]; then
25222529
host=${i/#*key_22_/}
25232530
host=${host/%.pub/}
2524-
[[ $host ]] && tmp+=("$host")
2531+
[[ $host ]] && known_hosts+=("$host")
25252532
fi
25262533
done
25272534
fi
25282535

25292536
# apply suffix and prefix
2530-
((${#tmp[@]})) &&
2531-
_comp_compgen -- -W '"${tmp[@]}"' -P "$prefix" -S "$suffix"
2537+
((${#known_hosts[@]})) &&
2538+
_comp_compgen -v known_hosts -- -W '"${known_hosts[@]}"' -P "$prefix" -S "$suffix"
25322539
fi
25332540

25342541
# append any available aliases from ssh config files
25352542
if [[ ${#config[@]} -gt 0 && $aliases ]]; then
25362543
local -a hosts
25372544
if _comp_split hosts "$(command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' "${config[@]}")"; then
2538-
_comp_compgen -a -- -P "$prefix" \
2545+
_comp_compgen -av known_hosts -- -P "$prefix" \
25392546
-S "$suffix" -W '"${hosts[@]%%[*?%]*}"' -X '@(\!*|)'
25402547
fi
25412548
fi
@@ -2548,38 +2555,37 @@ _known_hosts_real()
25482555
local generated=$(avahi-browse -cprak 2>/dev/null | awk -F';' \
25492556
'/^=/ && $5 ~ /^_(ssh|workstation)\._tcp$/ { print $7 }' |
25502557
sort -u)
2551-
_comp_compgen -a -- -P "$prefix" -S "$suffix" -W '$generated'
2558+
_comp_compgen -av known_hosts -- -P "$prefix" -S "$suffix" -W '$generated'
25522559
fi
25532560

25542561
# Add hosts reported by ruptime.
25552562
if type ruptime &>/dev/null; then
25562563
local generated=$(ruptime 2>/dev/null | awk '!/^ruptime:/ { print $1 }')
2557-
_comp_compgen -a -- -W '$generated'
2564+
_comp_compgen -av known_hosts -- -W '$generated'
25582565
fi
25592566

25602567
# Add results of normal hostname completion, unless
25612568
# `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
25622569
if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
2563-
_comp_compgen -a -- -A hostname -P "$prefix" -S "$suffix"
2570+
_comp_compgen -av known_hosts -- -A hostname -P "$prefix" -S "$suffix"
25642571
fi
25652572

2566-
if ((${#COMPREPLY[@]})); then
2573+
if ((${#known_hosts[@]})); then
25672574
if [[ $ipv4 ]]; then
2568-
COMPREPLY=("${COMPREPLY[@]/*:*$suffix/}")
2575+
known_hosts=("${known_hosts[@]/*:*$suffix/}")
25692576
fi
25702577
if [[ $ipv6 ]]; then
2571-
COMPREPLY=("${COMPREPLY[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}")
2578+
known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}")
25722579
fi
25732580
if [[ $ipv4 || $ipv6 ]]; then
2574-
for i in "${!COMPREPLY[@]}"; do
2575-
[[ ${COMPREPLY[i]} ]] || unset -v 'COMPREPLY[i]'
2581+
for i in "${!known_hosts[@]}"; do
2582+
[[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]'
25762583
done
25772584
fi
2585+
_comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}"
25782586
fi
25792587

2580-
_comp_ltrim_colon_completions "$prefix$cur"
2581-
2582-
} # _known_hosts_real()
2588+
} # _comp_compgen_known_hosts__impl()
25832589
complete -F _known_hosts traceroute traceroute6 \
25842590
fping fping6 telnet rsh rlogin ftp dig drill mtr ssh-installkeys showmount
25852591

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _comp_deprecate_func 2.12 _root_command _comp_root_command
1010
_comp_deprecate_func 2.12 _xfunc _comp_xfunc
1111
_comp_deprecate_func 2.12 _upvars _comp_upvars
1212
_comp_deprecate_func 2.12 _get_comp_words_by_ref _comp_get_words
13+
_comp_deprecate_func 2.12 _known_hosts_real _comp_compgen_known_hosts
1314
_comp_deprecate_func 2.12 _longopt _comp_longopt
1415
_comp_deprecate_func 2.12 __ltrim_colon_completions _comp_ltrim_colon_completions
1516
_comp_deprecate_func 2.12 _signals _comp_compgen_signals

completions/_xm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ _comp_cmd_xm()
9393
_comp_cmd_xm__domain_names
9494
;;
9595
3)
96-
_known_hosts_real -- "$cur"
96+
_comp_compgen_known_hosts -- "$cur"
9797
;;
9898
esac
9999
;;

completions/arping

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _comp_cmd_arping()
2424
return
2525
fi
2626

27-
_known_hosts_real -- "$cur"
27+
_comp_compgen_known_hosts -- "$cur"
2828
} &&
2929
complete -F _comp_cmd_arping arping
3030

completions/arpspoof

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ _comp_cmd_arpspoof()
1111
return
1212
;;
1313
-t)
14-
_known_hosts_real -- "$cur"
14+
_comp_compgen_known_hosts -- "$cur"
1515
return
1616
;;
1717
esac
1818

1919
if [[ $cur == -* ]]; then
2020
_comp_compgen_usage
2121
else
22-
_known_hosts_real -- "$cur"
22+
_comp_compgen_known_hosts -- "$cur"
2323
fi
2424

2525
} &&

completions/cancel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _comp_cmd_cancel()
77

88
case $prev in
99
-h)
10-
_known_hosts_real -- "$cur"
10+
_comp_compgen_known_hosts -- "$cur"
1111
return
1212
;;
1313
-U)

completions/chromium-browser

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _comp_cmd_chromium_browser()
1717
case $cur in
1818
*://*)
1919
local prefix="${cur%%://*}://"
20-
_known_hosts_real -- "${cur#*://}"
20+
_comp_compgen_known_hosts -- "${cur#*://}"
2121
COMPREPLY=("${COMPREPLY[@]/#/$prefix}")
2222
_comp_ltrim_colon_completions "$cur"
2323
;;

completions/chronyc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _comp_cmd_chronyc__command_args()
66
_comp_split args "$("$1" help 2>/dev/null |
77
awk '/^'"$prev"'\s[^ []/ { gsub("\\|", " ", $2); print $2 }')"
88
case $args in
9-
\<address\>) _known_hosts_real -- "$cur" ;;
9+
\<address\>) _comp_compgen_known_hosts -- "$cur" ;;
1010
\<*) ;;
1111
*) ((${#args[@]})) &&
1212
_comp_compgen -a -- -W '"${args[@]}"' ;;
@@ -23,7 +23,7 @@ _comp_cmd_chronyc()
2323
return
2424
;;
2525
-*h)
26-
_known_hosts_real -- "$cur"
26+
_comp_compgen_known_hosts -- "$cur"
2727
return
2828
;;
2929
esac
@@ -53,7 +53,7 @@ _comp_cmd_chronyc()
5353
fi
5454
;;
5555
2)
56-
[[ $prev == @(peer|server) ]] && _known_hosts_real -- "$cur"
56+
[[ $prev == @(peer|server) ]] && _comp_compgen_known_hosts -- "$cur"
5757
;;
5858
esac
5959
} &&

completions/curl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ _comp_cmd_curl()
7171
return
7272
;;
7373
--dns-servers | --noproxy)
74-
_known_hosts_real -- "${cur##*,}"
74+
_comp_compgen_known_hosts -- "${cur##*,}"
7575
((${#COMPREPLY[@]})) &&
7676
_comp_delimited , -W '"${COMPREPLY[@]}"'
7777
return
@@ -86,7 +86,7 @@ _comp_cmd_curl()
8686
;;
8787
--ftp-port | -${noargopts}P)
8888
_comp_compgen_available_interfaces -a
89-
_known_hosts_real -- "$cur"
89+
_comp_compgen -a known_hosts -- "$cur"
9090
_comp_compgen -a ip_addresses -a
9191
return
9292
;;
@@ -126,7 +126,7 @@ _comp_cmd_curl()
126126
;;
127127
--preproxy | --proxy | --socks4 | --socks4a | --socks5 | \
128128
--socks5-hostname | -${noargopts}x)
129-
_known_hosts_real -- "$cur"
129+
_comp_compgen_known_hosts -- "$cur"
130130
return
131131
;;
132132
--pubkey)

completions/dhclient

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _comp_cmd_dhclient()
1818
return
1919
;;
2020
-s)
21-
_known_hosts_real -- "$cur"
21+
_comp_compgen_known_hosts -- "$cur"
2222
return
2323
;;
2424
esac

0 commit comments

Comments
 (0)