Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: (5/3) _git: Make file-completion fallback optional



Jonas asserted that not everyone may like _git to fall back to file name
completion for sub-commands it doesn't know. This makes that behaviour
configurable. See the comment on top of _git for details.

The default is to *use* the fallbacke, since I am convinced that is the
least surprising way to do handle these situations. But if you really
dislike the fallback, now you can have it your way. With an indicator as
to *why* nothing is being completed even.
---
 Completion/Unix/Command/_git |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index a1856df..3fa1a73 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -17,6 +17,16 @@
 #
 # You could even create a function _git-foo() to handle specific completion
 # for that command.
+#
+# When git does not know a given sub-command (say `bar'), it falls back to
+# completing file names for all arguments to that sub command. I.e.:
+#
+#     % git bar <tab>
+#
+# ...will complete file names. If you do *not* want that fallback to be used,
+# use the `use-fallback' style like this:
+#
+#     % zstyle ':completion:*:*:git*:*' use-fallback false
 
 # TODO: There is still undocumented configurability in here.
 
@@ -6035,9 +6045,11 @@ _git() {
 
         if (( ${+functions[_git-$words[1]]} )); then
             _git-$words[1]
-        else
+        elif zstyle -T ":completion:${curcontext}:" use-fallback; then
             _path_files
             ret=$?
+        else
+            _message 'Unknown sub-command'
         fi
         ;;
     esac
-- 
1.7.6



Messages sorted by: Reverse Date, Date, Thread, Author