Skip to main content
1 of 4
intika
  • 15.1k
  • 8
  • 51
  • 85

ZSH Completion:

Zsh completion are done with scripts usually located at /usr/share/zsh/5.5/functions/Completion/Unix (may differ depending on the distro) each command completion's script is named _commandName, Zsh include/handle those scripts with the environment variable $fpath similar to the variable $PATH, in this case the used script is _git, the location order on $fpath is important as Zsh use the first _git script that it find and ignore the others if present (also similar to $PATH).

Scripting:

Like explained on this QA and as an example, the following function prepends $PWD/ to any relative path before passing it to _files, which is the normal completion function for files.

_absolute_files () { local expansion=$PREFIX$SUFFIX; expansion=${(e)expansion} if [[ "${expansion%%/#}" != "${expansion:a}" ]]; then PREFIX="\$PWD/$PREFIX" fi _files "$@"; } 

This works in many common cases, including recognizing paths starting with ~/ and such as absolute...

Solution:

The default git completion behavior does not include relative paths, we could edit its script like explained above to add support for relative path or we could simple replace the default git completion with the completion plugin gitfast from ohmyzsh with the following steps:

Clone ohmyzsh to some location (let say /location):

git clone https://github.com/ohmyzsh/ohmyzsh.git 

Edit ~/.zshrc and add at the bottom of the config file the following to include gitfast:

fpath=( /location/ohmyzsh/plugins/gitfast $fpath ) 

The order is important as explained before and here.

Update the completion cache by removing any ~/.zcompdump* then run compinit.

intika
  • 15.1k
  • 8
  • 51
  • 85