0

This is the completion code in my .zshrc:

autoload -U compinit
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots)       # Include hidden files.

I've been having a problem with the autocompletion when i use an alias: config='/usr/bin/git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'

This problem has been discussed and explained before (please check them they explain the problem better than i can) here and here, and the only reason that I'm mentioning this even though it's been discussed is because none of the solution work, and because there's these line of changes to the _git completion script that weren't there before:

        (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}}
        (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}}

These lines made the alias function but in one case only if the alias is written like i posted above it doesn't work but if the $HOME variables were replaced with ~ it works perfectly as it should the only problem is that if i do make that replacement the alias wouldn't work anymore and gives this error: fatal: not a git repository: '~/.local/share/dotfiles'

1 Answer 1

0

After investigating a bit I found out that it's a problem with the expansion of the $HOME variable, but the solution suggested here works perfectly, I just replaced --work-tree=$HOME with --work-tree ~ and it worked.

1
  • Nice :-) However please see the guidelines on writing a good answer in the Help center. You should present the entire solution in your answer to preserve it. If your link target disappears for whatever reason your answer becomes a lot less helpful. Mar 14, 2023 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .