From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 17/17] completion: allow to customize the completable command list
Date: Sun, 20 May 2018 20:40:09 +0200 [thread overview]
Message-ID: <20180520184009.976-18-pclouds@gmail.com> (raw)
In-Reply-To: <20180520184009.976-1-pclouds@gmail.com>
By default we show porcelain, external commands and a couple others
that are also popular. If you are not happy with this list, you can
now customize it a new config variable.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/config.txt | 8 +++++++
Documentation/git.txt | 3 ++-
contrib/completion/git-completion.bash | 2 +-
git.c | 2 ++
help.c | 33 ++++++++++++++++++++++++++
help.h | 1 +
6 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2659153cb3..9e81dcf867 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1343,6 +1343,14 @@ credential.<url>.*::
credentialCache.ignoreSIGHUP::
Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
+completion.commands::
+ This is only used by git-completion.bash to add or remove
+ commands from the list of completed commands. Normally only
+ porcelain commands and a few select others are completed. You
+ can add more commands, separated by space, in this
+ variable. Prefixing the command with '-' will remove it from
+ the existing list.
+
include::diff-config.txt[]
difftool.<tool>.path::
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 75f50d2379..6f7eddf847 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -170,7 +170,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
parse-options), main (all commands in libexec directory),
others (all other commands in `$PATH` that have git- prefix),
list-<category> (see categories in command-list.txt),
- nohelpers (exclude helper commands) and alias.
+ nohelpers (exclude helper commands), alias and config
+ (retrieve command list from config variable completion.commands)
GIT COMMANDS
------------
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 98f278fb9a..e5b2ccbdd2 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3012,7 +3012,7 @@ __git_main ()
then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else
- __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete)"
+ __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
fi
;;
esac
diff --git a/git.c b/git.c
index 63acd9ea81..447dac0e71 100644
--- a/git.c
+++ b/git.c
@@ -77,6 +77,8 @@ static int list_cmds(const char *spec)
exclude_helpers_from_list(&list);
else if (match_token(spec, len, "alias"))
list_aliases(&list);
+ else if (match_token(spec, len, "config"))
+ list_cmds_by_config(&list);
else if (len > 5 && !strncmp(spec, "list-", 5)) {
struct strbuf sb = STRBUF_INIT;
diff --git a/help.c b/help.c
index 23924dd300..abf87205b2 100644
--- a/help.c
+++ b/help.c
@@ -366,6 +366,39 @@ void list_cmds_by_category(struct string_list *list,
}
}
+void list_cmds_by_config(struct string_list *list)
+{
+ const char *cmd_list;
+
+ /*
+ * There's no actual repository setup at this point (and even
+ * if there is, we don't really care; only global config
+ * matters). If we accidentally set up a repository, it's ok
+ * too since the caller (git --list-cmds=) should exit shortly
+ * anyway.
+ */
+ if (git_config_get_string_const("completion.commands", &cmd_list))
+ return;
+
+ string_list_sort(list);
+ string_list_remove_duplicates(list, 0);
+
+ while (*cmd_list) {
+ struct strbuf sb = STRBUF_INIT;
+ const char *p = strchrnul(cmd_list, ' ');
+
+ strbuf_add(&sb, cmd_list, p - cmd_list);
+ if (*cmd_list == '-')
+ string_list_remove(list, cmd_list + 1, 0);
+ else
+ string_list_insert(list, sb.buf);
+ strbuf_release(&sb);
+ while (*p == ' ')
+ p++;
+ cmd_list = p;
+ }
+}
+
void list_common_guides_help(void)
{
struct category_description catdesc[] = {
diff --git a/help.h b/help.h
index b2293e99be..3b38292a1b 100644
--- a/help.h
+++ b/help.h
@@ -26,6 +26,7 @@ extern void list_all_main_cmds(struct string_list *list);
extern void list_all_other_cmds(struct string_list *list);
extern void list_cmds_by_category(struct string_list *list,
const char *category);
+extern void list_cmds_by_config(struct string_list *list);
extern const char *help_unknown_cmd(const char *cmd);
extern void load_command_list(const char *prefix,
struct cmdnames *main_cmds,
--
2.17.0.705.g3525833791
prev parent reply other threads:[~2018-05-20 18:41 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 4:27 [PATCH 00/14] nd/command-list updates Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 01/14] generate-cmds.sh: factor out synopsis extract code Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 02/14] generate-cmds.sh: export all commands to command-list.h Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 03/14] help: use command-list.h for common command list Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 04/14] Remove common-cmds.h Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 05/14] git.c: convert --list-* to --list-cmds=* Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 06/14] git --list-cmds: collect command list in a string_list Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 07/14] completion: implement and use --list-cmds=main,others Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 08/14] git: support --list-cmds=list-<category> Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 09/14] help: add "-a --verbose" to list all commands with synopsis Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 10/14] help: use command-list.txt for the source of guides Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 11/14] command-list.txt: documentation and guide line Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 12/14] completion: let git provide the completable command list Nguyễn Thái Ngọc Duy
2018-05-20 13:20 ` SZEDER Gábor
2018-05-20 15:57 ` Duy Nguyen
2018-05-19 4:27 ` [PATCH 13/14] completion: reduce " Nguyễn Thái Ngọc Duy
2018-05-20 13:24 ` SZEDER Gábor
2018-05-21 1:06 ` Junio C Hamano
2018-05-19 4:27 ` [PATCH 14/14] completion: allow to customize the " Nguyễn Thái Ngọc Duy
2018-05-20 14:27 ` SZEDER Gábor
2018-05-20 15:52 ` Duy Nguyen
2018-05-20 18:39 ` [PATCH v2 00/17] nd/command-list updates Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 01/17] generate-cmds.sh: factor out synopsis extract code Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 02/17] generate-cmds.sh: export all commands to command-list.h Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 03/17] help: use command-list.h for common command list Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 04/17] Remove common-cmds.h Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 05/17] git.c: convert --list-* to --list-cmds=* Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 06/17] git --list-cmds: collect command list in a string_list Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 07/17] completion: implement and use --list-cmds=main,others Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 08/17] git: support --list-cmds=list-<category> Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 09/17] help: add "-a --verbose" to list all commands with synopsis Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 10/17] help: use command-list.txt for the source of guides Nguyễn Thái Ngọc Duy
2018-11-20 19:34 ` Ævar Arnfjörð Bjarmason
2018-05-20 18:40 ` [PATCH v2 11/17] command-list.txt: documentation and guide line Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 12/17] completion: let git provide the completable command list Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 13/17] completion: reduce " Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 14/17] Move declaration for alias.c to alias.h Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 15/17] completion: add and use --list-cmds=nohelpers Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 16/17] completion: add and use --list-cmds=alias Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` Nguyễn Thái Ngọc Duy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180520184009.976-18-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).