ZSH completion for git does not autocomplete absolute path?
Zsh can complete absolute paths just fine. Just try ls /etc/fs
Tab.
The problem lies with whatever _git
completer you are using. (See footnote below.)
You can test this as follows:
- Make sure you have initialized
compinit
:
autoload -Uz compinit && compinit
- Type
git diff
(with a space at the end) and press CtrlX, followed by the letter H.
I get the following output:
tags in context :completion::complete:git-diff::
argument-rest options (_arguments _git-diff _git)
tags in context :completion::complete:git-diff:argument-rest:
commit-ranges blobs-and-trees-in-treeish files blobs (_git-diff _git)
heads commit-tags commit-objects (__git_commits __git_commit_ranges _git-diff _git)
heads-local heads-remote (__git_heads __git_commits __git_commit_ranges _git-diff _git)
messages (_message __git_command_successful __git_heads_local __git_heads __git_commits __git_commit_ranges _git-diff _git)
heads-local (__git_describe_branch __git_describe_commit __git_heads_local __git_heads __git_commits __git_commit_ranges _git-diff _git)
heads-remote (__git_describe_branch __git_describe_commit __git_heads_remote __git_heads __git_commits __git_commit_ranges _git-diff _git)
messages (_message __git_command_successful __git_tags_of_type __git_commit_tags __git_commits __git_commit_ranges _git-diff _git)
messages (_message __git_command_successful __git_recent_commits __git_commit_objects_prefer_recent __git_commits __git_commit_ranges _git-diff _git)
changed-in-working-tree-files (__git_changed-in-working-tree_files _git-diff _git)
blob-tags blob-objects (__git_blobs _git-diff _git)
messages (_message __git_command_successful __git_tags_of_type __git_blob_tags __git_blobs _git-diff _git)
tags in context :completion::complete:git::
argument-rest (_arguments _git)
Note that this does not include files
, directories
or globbed-files
(which you will see when you type ls
, followed by CtrlX+H). What it does include is changed-in-working-tree-files
, which are generated by git diff -z --name-only --no-color
(as you can see here), which produces paths that are relative to the root of the repo and not absolute paths.
Ergo, your absolute path will not get completed in the git
context as it does not have the info there to do so.
Footnote: Are you using Zsh's own _git
completer or one that might have been installed by Git? I highly recommend not using the one installed by Git, as it is not properly implemented by Zsh standards and thus rather buggy in certain parts. (It appears to be some kind of automatic – and flawed – port from Git's completer for Bash.) Check your fpath
for any completer file called _git
that doesn't belong to Zsh's installation and remove it.