From: Ron Panduwana <panduwana@gmail.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
Junio C Hamano <gitster@pobox.com>,
Lee Marlow <lee.marlow@gmail.com>,
Thomas Rast <trast@student.ethz.ch>,
Ron Panduwana <panduwana@gmail.com>
Subject: [PATCH v2] Make use of git status when autocompleting git add, rm, checkout --, and reset HEAD
Date: Wed, 31 Aug 2011 04:43:03 +0700 [thread overview]
Message-ID: <1314740583-14567-1-git-send-email-panduwana@gmail.com> (raw)
Signed-off-by: Ron Panduwana <panduwana@gmail.com>
---
On Fri, Aug 19, 2011 at 5:10 PM, Thomas Rast <trast@student.ethz.ch> wrote:
> Some thoughts:
>
> * running git-status for . has some issues: it doesn't work in the
> Â case of
>
> Â Â cd subdir
> Â Â git add ../some/file[TAB]
>
> Â It's also inefficient if you are at the top level and
>
> Â Â git add path/to/file/a/few/levels/down[TAB]
>
> Â since it wouldn't actually have to look for untracked files in the
> Â entire repo.
Fixed by running git-status for $cur if $cur is a directory. Otherwise run on .
> * -uall is not required unless you are looking for untracked files.
> Â For the other commands you could speed up completion by passing
> Â -uno instead.
Fixed by adding second parameter to __git_files_having_status
contrib/completion/git-completion.bash | 84 ++++++++++++++++++++-----------
1 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8648a36..9d44501 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1010,6 +1010,16 @@ __git_has_doubledash ()
return 1
}
+# __git_files_having_status requires 2 arguments
+__git_files_having_status ()
+{
+ local dir="."
+ if [ -d "$cur" ]; then
+ dir="$cur"
+ fi
+ echo "$(git status $2 -s "$dir" 2>/dev/null | egrep "^$1" | cut -c4-)"
+}
+
__git_whitespacelist="nowarn warn error error-all fix"
_git_am ()
@@ -1058,17 +1068,17 @@ _git_apply ()
_git_add ()
{
- __git_has_doubledash && return
-
- case "$cur" in
- --*)
- __gitcomp "
- --interactive --refresh --patch --update --dry-run
- --ignore-errors --intent-to-add
- "
- return
- esac
- COMPREPLY=()
+ if ! __git_has_doubledash; then
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --interactive --refresh --patch --update --dry-run
+ --ignore-errors --intent-to-add
+ "
+ return
+ esac
+ fi
+ __gitcomp "$(__git_files_having_status "(.[MAU]|UD|\?\?)" -uall)"
}
_git_archive ()
@@ -1171,7 +1181,12 @@ _git_bundle ()
_git_checkout ()
{
- __git_has_doubledash && return
+ if __git_has_doubledash; then
+ if [[ ${words[2]} = "--" ]]; then
+ __gitcomp "$(__git_files_having_status ".[MD]" -uno)"
+ fi
+ return
+ fi
case "$cur" in
--conflict=*)
@@ -1469,7 +1484,7 @@ _git_help ()
__gitcomp "$__git_all_commands $(__git_aliases)
attributes cli core-tutorial cvs-migration
diffcore gitk glossary hooks ignore modules
- namespaces repository-layout tutorial tutorial-2
+ repository-layout tutorial tutorial-2
workflows
"
}
@@ -2313,14 +2328,18 @@ _git_replace ()
_git_reset ()
{
- __git_has_doubledash && return
-
- case "$cur" in
- --*)
- __gitcomp "--merge --mixed --hard --soft --patch"
+ if ! __git_has_doubledash; then
+ case "$cur" in
+ --*)
+ __gitcomp "--merge --mixed --hard --soft --patch"
+ return
+ ;;
+ esac
+ fi
+ if [[ ${words[2]} = "HEAD" ]]; then
+ __gitcomp "$(__git_files_having_status "[ADM]." -uno)"
return
- ;;
- esac
+ fi
__gitcomp "$(__git_refs)"
}
@@ -2337,15 +2356,20 @@ _git_revert ()
_git_rm ()
{
- __git_has_doubledash && return
-
- case "$cur" in
- --*)
- __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
- return
- ;;
- esac
- COMPREPLY=()
+ if ! __git_has_doubledash; then
+ case "$cur" in
+ --*)
+ __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
+ return
+ ;;
+ esac
+ fi
+ # check if --cached was specified
+ if [ "$(__git_find_on_cmdline "--cached")" ]; then
+ COMPREPLY=()
+ else
+ __gitcomp "$(__git_files_having_status "(.D|DU|UA)" -uno)"
+ fi
}
_git_shortlog ()
@@ -2640,7 +2664,6 @@ _git ()
--exec-path
--html-path
--work-tree=
- --namespace=
--help
"
;;
@@ -2737,3 +2760,4 @@ else
shopt "$@"
}
fi
+
--
1.7.1
next reply other threads:[~2011-08-30 21:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 21:43 Ron Panduwana [this message]
2011-08-30 23:14 ` [PATCH v2] Make use of git status when autocompleting git add, rm, checkout --, and reset HEAD Junio C Hamano
2011-09-06 17:43 ` SZEDER Gábor
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314740583-14567-1-git-send-email-panduwana@gmail.com \
--to=panduwana@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=lee.marlow@gmail.com \
--cc=spearce@spearce.org \
--cc=trast@student.ethz.ch \
/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.
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).