Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created December 21, 2011 06:38
Show Gist options
  • Save tomykaira/1504938 to your computer and use it in GitHub Desktop.
Save tomykaira/1504938 to your computer and use it in GitHub Desktop.
git-completion.bash | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/git-completion.bash b/git-completion.bash
index b7c1edf..ca41f34 100755
--- a/git-completion.bash
+++ b/git-completion.bash
@@ -1057,6 +1057,32 @@ _git_apply ()
COMPREPLY=()
}
+__git_changed_files ()
+{
+ local IFSBAK=$IFS
+ local IFS="
+"
+ for f in $(git status --short 2>/dev/null); do
+ case `echo $f | cut -c -2` in
+ ' D' | ' M' ) echo "$f" | cut -c 4- ;;
+ esac
+ done
+ IFS=$IFSBAK
+}
+
+__git_unstaged_files ()
+{
+ local IFSBAK=$IFS
+ local IFS="
+"
+ for f in $(git status --short 2>/dev/null); do
+ case `echo $f | cut -c -2` in
+ ' M' | '??' ) echo "$f" | cut -c 4- ;;
+ esac
+ done
+ IFS=$IFSBAK
+}
+
_git_add ()
{
__git_has_doubledash && return
@@ -1068,6 +1094,11 @@ _git_add ()
--ignore-errors --intent-to-add
"
return
+ ;;
+ *)
+ __gitcomp "$(__git_unstaged_files)"
+ return
+ ;;
esac
COMPREPLY=()
}
@@ -1172,7 +1203,10 @@ _git_bundle ()
_git_checkout ()
{
- __git_has_doubledash && return
+ if __git_has_doubledash ; then
+ __gitcomp "$(__git_changed_files)"
+ return
+ fi
case "$cur" in
--conflict=*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment