Skip to content

Commit e11dca1

Browse files
pcloudsgitster
authored andcommitted
completion: add and use --list-cmds=nohelpers
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 65b5f94 commit e11dca1

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
169169
groups are: builtins, parseopt (builtin commands that use
170170
parse-options), main (all commands in libexec directory),
171171
others (all other commands in `$PATH` that have git- prefix),
172-
list-<category> (see categories in command-list.txt)
172+
list-<category> (see categories in command-list.txt),
173+
nohelpers (exclude helper commands).
173174

174175
GIT COMMANDS
175176
------------

contrib/completion/git-completion.bash

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -843,35 +843,23 @@ __git_commands () {
843843
then
844844
printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
845845
else
846-
git --list-cmds=list-mainporcelain,others,list-complete
846+
git --list-cmds=list-mainporcelain,others,nohelpers,list-complete
847847
fi
848848
;;
849849
all)
850850
if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
851851
then
852852
printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST"
853853
else
854-
git --list-cmds=main,others
854+
git --list-cmds=main,others,nohelpers
855855
fi
856856
;;
857857
esac
858858
}
859859

860-
__git_list_commands ()
861-
{
862-
local i IFS=" "$'\n'
863-
for i in $(__git_commands $1)
864-
do
865-
case $i in
866-
*--*) : helper pattern;;
867-
*) echo $i;;
868-
esac
869-
done
870-
}
871-
872860
__git_list_all_commands ()
873861
{
874-
__git_list_commands all
862+
__git_commands all
875863
}
876864

877865
__git_all_commands=
@@ -883,7 +871,7 @@ __git_compute_all_commands ()
883871

884872
__git_list_porcelain_commands ()
885873
{
886-
__git_list_commands porcelain
874+
__git_commands porcelain
887875
}
888876

889877
__git_porcelain_commands=

git.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ static int use_pager = -1;
3939

4040
static void list_builtins(struct string_list *list, unsigned int exclude_option);
4141

42+
static void exclude_helpers_from_list(struct string_list *list)
43+
{
44+
int i = 0;
45+
46+
while (i < list->nr) {
47+
if (strstr(list->items[i].string, "--"))
48+
unsorted_string_list_delete_item(list, i, 0);
49+
else
50+
i++;
51+
}
52+
}
53+
4254
static int match_token(const char *spec, int len, const char *token)
4355
{
4456
int token_len = strlen(token);
@@ -61,6 +73,8 @@ static int list_cmds(const char *spec)
6173
list_all_main_cmds(&list);
6274
else if (match_token(spec, len, "others"))
6375
list_all_other_cmds(&list);
76+
else if (match_token(spec, len, "nohelpers"))
77+
exclude_helpers_from_list(&list);
6478
else if (len > 5 && !strncmp(spec, "list-", 5)) {
6579
struct strbuf sb = STRBUF_INIT;
6680

0 commit comments

Comments
 (0)