* [PATCH 1/3] completion: complete config variables for --get/getall/unset/unset-all
@ 2009-05-07 6:15 Stephen Boyd
2009-05-07 6:15 ` [PATCH 2/3] completion: add find_argument_and_value() function Stephen Boyd
2009-05-07 6:18 ` Stephen Boyd
0 siblings, 2 replies; 7+ messages in thread
From: Stephen Boyd @ 2009-05-07 6:15 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
This should make it easier for users to get and unset their
configuration variables without having to open documentation or dig
through their configuration file.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
contrib/completion/git-completion.bash | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1683e6d..72a16a1 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1322,6 +1322,17 @@ _git_send_email ()
COMPREPLY=()
}
+__git_config_get_set_variables ()
+{
+ for i in $(git --git-dir="$(__gitdir)" config --list); do
+ case "$i" in
+ *.*)
+ echo "${i/=*/}"
+ ;;
+ esac
+ done
+}
+
_git_config ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1388,6 +1399,10 @@ _git_config ()
__gitcomp "$__git_send_email_suppresscc_options"
return
;;
+ --get|--get-all|--unset|--unset-all)
+ __gitcomp "$(__git_config_get_set_variables)"
+ return
+ ;;
*.*)
COMPREPLY=()
return
--
1.6.3.rc4.29.g8146
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] completion: add find_argument_and_value() function
2009-05-07 6:15 [PATCH 1/3] completion: complete config variables for --get/getall/unset/unset-all Stephen Boyd
@ 2009-05-07 6:15 ` Stephen Boyd
2009-05-07 6:18 ` Stephen Boyd
1 sibling, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2009-05-07 6:15 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
Add a function to get arguments and their associated value. This is used
by the config completion to find config file arguments.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
I'm not sure if this is correct. It works for the case I have, but
others I'm not so sure. Let's just say I'm no bash expert.
contrib/completion/git-completion.bash | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 72a16a1..f179cc8 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -618,6 +618,31 @@ __git_find_subcommand ()
done
}
+# __git_find_argument_and_value requires 1 argument
+__git_find_argument_and_value ()
+{
+ local word nextword argument c=1
+
+ while [ $c -lt $COMP_CWORD ]; do
+ word="${COMP_WORDS[c]}"
+ for argument in $1; do
+ if [ "${argument##--}" = "${word##--}" ]; then
+ nextword=${COMP_WORDS[$((c+1))]}
+ if [ "${nextword#-}" != "$nextword" ]; then
+ nextword=
+ fi
+ echo "$argument $nextword"
+ return
+ fi
+ if [ "${argument/=*/}" = "${word/=*/}" ]; then
+ echo "$word"
+ return
+ fi
+ done
+ c=$((++c))
+ done
+}
+
__git_has_doubledash ()
{
local c=1
--
1.6.3.rc4.29.g8146
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] completion: add find_argument_and_value() function
2009-05-07 6:15 [PATCH 1/3] completion: complete config variables for --get/getall/unset/unset-all Stephen Boyd
2009-05-07 6:15 ` [PATCH 2/3] completion: add find_argument_and_value() function Stephen Boyd
@ 2009-05-07 6:18 ` Stephen Boyd
2009-05-07 6:18 ` [PATCH 3/3] completion: use specified file (if any) when completing config vars Stephen Boyd
1 sibling, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2009-05-07 6:18 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
Add a function to get arguments and their associated value. This is used
by the config completion to find config file arguments.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
I'm not sure if this is correct. It works for the case I have, but
others I'm not so sure. Let's just say I'm no bash expert.
contrib/completion/git-completion.bash | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 72a16a1..f179cc8 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -618,6 +618,31 @@ __git_find_subcommand ()
done
}
+# __git_find_argument_and_value requires 1 argument
+__git_find_argument_and_value ()
+{
+ local word nextword argument c=1
+
+ while [ $c -lt $COMP_CWORD ]; do
+ word="${COMP_WORDS[c]}"
+ for argument in $1; do
+ if [ "${argument##--}" = "${word##--}" ]; then
+ nextword=${COMP_WORDS[$((c+1))]}
+ if [ "${nextword#-}" != "$nextword" ]; then
+ nextword=
+ fi
+ echo "$argument $nextword"
+ return
+ fi
+ if [ "${argument/=*/}" = "${word/=*/}" ]; then
+ echo "$word"
+ return
+ fi
+ done
+ c=$((++c))
+ done
+}
+
__git_has_doubledash ()
{
local c=1
--
1.6.3.rc4.29.g8146
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] completion: use specified file (if any) when completing config vars
2009-05-07 6:18 ` Stephen Boyd
@ 2009-05-07 6:18 ` Stephen Boyd
2009-05-07 15:12 ` Shawn O. Pearce
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2009-05-07 6:18 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
Only list the variables that can actually be affected by the command by
searching the arguments for a config file setting.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
contrib/completion/git-completion.bash | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index f179cc8..8a9863b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1349,7 +1349,10 @@ _git_send_email ()
__git_config_get_set_variables ()
{
- for i in $(git --git-dir="$(__gitdir)" config --list); do
+ local args="--global --system --file= -f"
+ local config_file="$(__git_find_argument_and_value "$args")"
+ for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
+ 2>/dev/null); do
case "$i" in
*.*)
echo "${i/=*/}"
--
1.6.3.rc4.29.g8146
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] completion: use specified file (if any) when completing config vars
2009-05-07 6:18 ` [PATCH 3/3] completion: use specified file (if any) when completing config vars Stephen Boyd
@ 2009-05-07 15:12 ` Shawn O. Pearce
2009-05-07 19:55 ` Stephen Boyd
0 siblings, 1 reply; 7+ messages in thread
From: Shawn O. Pearce @ 2009-05-07 15:12 UTC (permalink / raw)
To: Stephen Boyd; +Cc: git
Stephen Boyd <bebarino@gmail.com> wrote:
> Only list the variables that can actually be affected by the command by
> searching the arguments for a config file setting.
Wow, this is a lot of magic.
Try:
git config --global remote.gitster.url $(git config remote.o<TAB>
You'll complete against --global, not the local repository.
> __git_config_get_set_variables ()
> {
> - for i in $(git --git-dir="$(__gitdir)" config --list); do
> + local args="--global --system --file= -f"
> + local config_file="$(__git_find_argument_and_value "$args")"
> + for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
> + 2>/dev/null); do
--
Shawn.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] completion: use specified file (if any) when completing config vars
2009-05-07 15:12 ` Shawn O. Pearce
@ 2009-05-07 19:55 ` Stephen Boyd
2009-05-09 1:00 ` Stephen Boyd
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2009-05-07 19:55 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
On Thu, May 7, 2009 at 8:12 AM, Shawn O. Pearce <spearce@spearce.org> wrote:
> Stephen Boyd <bebarino@gmail.com> wrote:
>> Only list the variables that can actually be affected by the command by
>> searching the arguments for a config file setting.
>
> Wow, this is a lot of magic.
>
> Try:
>
> git config --global remote.gitster.url $(git config remote.o<TAB>
>
> You'll complete against --global, not the local repository.
>
Yeah, I didn't think it would be very robust. Is it a good idea to
keep going down this path, or is it too magical? This example could be
fixed by searching the words backwards, but I imagine there is some
other case where that will fail. Also, --global and --system don't
have values, so right now it's all wrong (i.e. config_file is
"--global remote.gitster.url" for this example).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] completion: use specified file (if any) when completing config vars
2009-05-07 19:55 ` Stephen Boyd
@ 2009-05-09 1:00 ` Stephen Boyd
0 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2009-05-09 1:00 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
Stephen Boyd wrote:
> On Thu, May 7, 2009 at 8:12 AM, Shawn O. Pearce <spearce@spearce.org> wrote:
>> Wow, this is a lot of magic.
>>
>> Try:
>>
>> Â git config --global remote.gitster.url $(git config remote.o<TAB>
>>
>> You'll complete against --global, not the local repository
>
> Yeah, I didn't think it would be very robust. Is it a good idea to
> keep going down this path, or is it too magical? This example could be
> fixed by searching the words backwards, but I imagine there is some
> other case where that will fail. Also, --global and --system don't
> have values, so right now it's all wrong (i.e. config_file is
> "--global remote.gitster.url" for this example).
After further investigation, I can't get the tab completion you talk
about here to work at all. Should it work?
I've reworked this into two patches which I'll send as a follow up soon.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-05-09 1:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-07 6:15 [PATCH 1/3] completion: complete config variables for --get/getall/unset/unset-all Stephen Boyd
2009-05-07 6:15 ` [PATCH 2/3] completion: add find_argument_and_value() function Stephen Boyd
2009-05-07 6:18 ` Stephen Boyd
2009-05-07 6:18 ` [PATCH 3/3] completion: use specified file (if any) when completing config vars Stephen Boyd
2009-05-07 15:12 ` Shawn O. Pearce
2009-05-07 19:55 ` Stephen Boyd
2009-05-09 1:00 ` Stephen Boyd
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 NNTP newsgroup(s).