Skip to content

Commit 77074a9

Browse files
authored
Merge pull request #978 from scop/feat/no-empty-cmd
feat: no empty command completion if `no_empty_cmd_completion` is on
2 parents 8d5d742 + 214c85e commit 77074a9

28 files changed

+101
-49
lines changed

bash_completion

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,8 +2596,7 @@ _comp_command_offset()
25962596
_comp_get_words cur
25972597

25982598
if ((COMP_CWORD == 0)); then
2599-
compopt -o filenames
2600-
_comp_compgen -- -d -c
2599+
_comp_compgen_commands
26012600
else
26022601
_comp_dequote "${COMP_WORDS[0]}" || ret=${COMP_WORDS[0]}
26032602
local cmd=$ret compcmd=$ret
@@ -2717,6 +2716,19 @@ _complete_as_root()
27172716
[[ $EUID -eq 0 || ${root_command-} ]]
27182717
}
27192718

2719+
# Complete on available commands, subject to `no_empty_cmd_completion`.
2720+
# @return True (0) if one or more completions are generated, or otherwise False
2721+
# (1). Note that it returns 1 even when the completion generation is canceled
2722+
# by `shopt -s no_empty_cmd_completion`.
2723+
#
2724+
# @since 2.12
2725+
_comp_compgen_commands()
2726+
{
2727+
[[ ! ${cur-} ]] && shopt -q no_empty_cmd_completion && return 1
2728+
# -o filenames for e.g. spaces in paths to and in command names
2729+
_comp_compgen -- -c -o plusdirs && compopt -o filenames
2730+
}
2731+
27202732
# @since 2.12
27212733
_comp_longopt()
27222734
{

completions/_su

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ _comp_cmd_su()
1919
return
2020
;;
2121
-c | --command | --session-command)
22-
compopt -o filenames
23-
_comp_compgen -- -d -c
22+
_comp_compgen_commands
2423
return
2524
;;
2625
esac

completions/_svn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ _comp_cmd_svn()
3838
return
3939
;;
4040
--editor-cmd | --diff-cmd | --diff3-cmd)
41-
compopt -o filenames
42-
_comp_compgen -- -c
41+
_comp_compgen_commands
4342
return
4443
;;
4544
esac

completions/cpio

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ _comp_cmd_cpio()
2222
return
2323
;;
2424
--rsh-command)
25-
compopt -o filenames
26-
_comp_compgen -- -c
25+
_comp_compgen_commands
2726
return
2827
;;
2928
esac

completions/dpkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ _comp_cmd_dpkg()
130130
return
131131
;;
132132
--status-logger)
133-
_comp_compgen -- -c
133+
_comp_compgen_commands
134134
return
135135
;;
136136
--verify-format)

completions/fio

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ _comp_cmd_fio()
7474
return
7575
;;
7676
--trigger | --trigger-remote)
77-
compopt -o filenames
78-
_comp_compgen -- -c
77+
_comp_compgen_commands
7978
return
8079
;;
8180
--aux-path)
@@ -88,7 +87,7 @@ _comp_cmd_fio()
8887
return
8988
;;
9089
--exec_postrun | --exec_prerun)
91-
_comp_compgen -- -c
90+
_comp_compgen_commands
9291
return
9392
;;
9493
--uid)

completions/firefox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ _comp_cmd_firefox()
3333
return
3434
;;
3535
--debugger | -d)
36-
_comp_compgen -- -c
36+
_comp_compgen_commands
3737
return
3838
;;
3939
esac

completions/gdb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _comp_cmd_gdb()
2020
if _comp_looks_like_path "$cur"; then
2121
# compgen -c works as expected if $cur contains any slashes.
2222
local PATH="$PATH:."
23-
_comp_compgen -- -d -c
23+
_comp_compgen_commands
2424
else
2525
# otherwise compgen -c contains Bash's built-in commands,
2626
# functions and aliases. Thus we need to retrieve the program

completions/man

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ _comp_cmd_man()
2929
return
3030
;;
3131
--pager | -${noargopts}P)
32-
compopt -o filenames
33-
_comp_compgen -- -c
32+
_comp_compgen_commands
3433
return
3534
;;
3635
--preprocessor | -${noargopts}p)

completions/mr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ _comp_cmd_mr()
5555
return
5656
;;
5757
run)
58-
_comp_compgen -- -c
58+
_comp_compgen_commands
5959
return
6060
;;
6161
*)

0 commit comments

Comments
 (0)