zsh-workers
 help / color / mirror / code / Atom feed
* [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
@ 2023-03-09 12:33 eliasghafari
  2023-03-09 17:12 ` Bart Schaefer
  2023-03-09 19:27 ` Oliver Kiddle
  0 siblings, 2 replies; 8+ messages in thread
From: eliasghafari @ 2023-03-09 12:33 UTC (permalink / raw)
  To: zsh-workers

Hello,

I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",
completion for the commands works perfectly, e.g:
config ad<tab>
config add

config rm --ca<tab>
config rm --cached

But when it comes to filenames the autocompletion e.g:
in a normal git repo:
git rm --cached <tab> will show all the files that could be removed from
the index. And
git add <tab> will show all the files that were modified or created.

While using git bare repo:
config rm --cached <tab> doesn't show anything.
config add <tab> also shows nothing

So after investigating a bit, I found that the problem lied in the
expansion of the address of the git-dir and I found that by modifying
this line:
(( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".

I fixed this by replacing the Q modifier with e, but please note that I
have no idea how the zsh completion system works and I fixed this by
simply trying every modifier and seeing which one works.

After making that replacement,
config rm --cached <tab> shows what can be removed from the index, and
config add <tab> works too.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
@ 2023-03-09 17:12 ` Bart Schaefer
  2023-03-09 19:27 ` Oliver Kiddle
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2023-03-09 17:12 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

On Thu, Mar 9, 2023 at 4:42 AM eliasghafari <eliasghafari@disroot.org> wrote:
>
> I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",
> [...]
> (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
> which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".
>
> I fixed this by replacing the Q modifier with e

The Q modifier is just cleaning up quotes, so you probably don't want
to remove that.  I think the right thing would be to change
${(Q)${~opt_args[--git-dir]}} to ${(Q)${(e)~opt_args[--git-dir]}} but
I would defer to Daniel or Oliver to confirm.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
  2023-03-09 17:12 ` Bart Schaefer
@ 2023-03-09 19:27 ` Oliver Kiddle
  2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
  1 sibling, 2 replies; 8+ messages in thread
From: Oliver Kiddle @ 2023-03-09 19:27 UTC (permalink / raw)
  To: eliasghafari; +Cc: zsh-workers

eliasghafari wrote:
> I'm using a git bare repo to manage my files with this alias: "alias config='git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME'",

> While using git bare repo:
> config rm --cached <tab> doesn't show anything.

> So after investigating a bit, I found that the problem lied in the
> expansion of the address of the git-dir and I found that by modifying
> this line:
> (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} && printf("\n${(Q)${~opt_args[--git-dir]}}\n")
> which shows that the address passed to GIT_DIR is "$HOME/.local/share/dotfiles" without the "$HOME" being expanded to "/home/user".
>
> I fixed this by replacing the Q modifier with e, but please note that I

I would suggest you try using ~ instead of $HOME in your alias:

  alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'

The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.
While using (e) is arguably the right thing to do, it will expand things
like command-substitution and we've always intentionally shied away
from expanding anything that could have side-effects when parsing the
command-line for completion.

The modifiers don't allow you to pick-and-choose expansions so there
isn't a trivial way to expand variable references without expanding more
problematic things.

Oliver


^ permalink raw reply	[flat|nested] 8+ messages in thread

* The (e) parameter flag and side-effects
  2023-03-09 19:27 ` Oliver Kiddle
@ 2023-03-09 23:54   ` Bart Schaefer
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2023-03-09 23:54 UTC (permalink / raw)
  To: Zsh hackers list

On Thu, Mar 9, 2023 at 11:28 AM Oliver Kiddle <opk@zsh.org> wrote:
>
> While using (e) is arguably the right thing to do, it will expand things
> like command-substitution and we've always intentionally shied away
> from expanding anything that could have side-effects when parsing the
> command-line for completion.

We could add a flag for that, though, I think; it would just need to
do the same trick I applied to subscript values in named references,
that is, toggle the EXECOPT flag off and back on around (or in) the
call to subst_parse_str().


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-09 19:27 ` Oliver Kiddle
  2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
@ 2023-03-10 10:07   ` Elias Ghafari
  2023-03-10 10:12     ` Roman Perepelitsa
  1 sibling, 1 reply; 8+ messages in thread
From: Elias Ghafari @ 2023-03-10 10:07 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

On 23/03/09 08:27PM, Oliver Kiddle wrote:
> 
> I would suggest you try using ~ instead of $HOME in your alias:
> 
>   alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'
> 
> The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.

I have actually tried that before and i noticed that the completion
works as if i had put the (e), but the problem is, while the completion
works the command itself doesn't and returns an error saying that
'~/.local/share/dotfiles` isn't a git repo:
fatal: not a git repository: '~/.local/share/dotfiles'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
@ 2023-03-10 10:12     ` Roman Perepelitsa
  2023-09-11 15:05       ` Elias Ghafari
  0 siblings, 1 reply; 8+ messages in thread
From: Roman Perepelitsa @ 2023-03-10 10:12 UTC (permalink / raw)
  To: Elias Ghafari; +Cc: Oliver Kiddle, zsh-workers

On Fri, Mar 10, 2023 at 11:08 AM Elias Ghafari <eliasghafari@disroot.org> wrote:
>
> On 23/03/09 08:27PM, Oliver Kiddle wrote:
> >
> > I would suggest you try using ~ instead of $HOME in your alias:
> >
> >   alias config='git --git-dir=~/.local/share/dotfiles --work-tree=~'
> >
> > The tilde in ${~opt_args[--git-dir]}} ensures that tildes are expanded.
>
> I have actually tried that before and i noticed that the completion
> works as if i had put the (e), but the problem is, while the completion
> works the command itself doesn't and returns an error saying that
> '~/.local/share/dotfiles` isn't a git repo:
> fatal: not a git repository: '~/.local/share/dotfiles'

You can either replace `--work-tree=~` with `--work-tree ~` or set
magic_equal_subst. I'd do the former.

Roman.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-03-10 10:12     ` Roman Perepelitsa
@ 2023-09-11 15:05       ` Elias Ghafari
  2023-09-12  2:26         ` Jun T
  0 siblings, 1 reply; 8+ messages in thread
From: Elias Ghafari @ 2023-09-11 15:05 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Oliver Kiddle, zsh-workers

On 23/03/10 11:12AM, Roman Perepelitsa wrote:
> You can either replace `--work-tree=~` with `--work-tree ~` or set
> magic_equal_subst. I'd do the former.

Hello again,

This solution worked perfectly until a month or so ago, but then it
stopped working.
I still use the same alias:
config='git --git-dir=$HOME/.local/share/dotfiles --work-tree ~' 

I don't know what has changed but $HOME is not expanding and executing
`zsh 2>log` returns this after trying `config diff <Tab>`:
fatal: not a git repository: '$HOME/.local/share/dotfiles'

Which is weird this error happened the last time on git's side saying
that '~/.local/share/dotfiles' is not a git repo when I replaced $HOME
with ~. But as you can see this resulted from Zsh.
Any idea of what has changed to cause this, and if this can be solved ?

Thanks,
Elias.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...)
  2023-09-11 15:05       ` Elias Ghafari
@ 2023-09-12  2:26         ` Jun T
  0 siblings, 0 replies; 8+ messages in thread
From: Jun T @ 2023-09-12  2:26 UTC (permalink / raw)
  To: zsh-workers


> 2023/09/12 0:05, Elias Ghafari <eliasghafari@disroot.org> wrote:
> 
> This solution worked perfectly until a month or so ago,

I have no idea why it was working, but are there any reasons that you
want to use '...' instead of "..."? Or am I missing something?

alias config="git --git-dir=$HOME/.local/share/dotfiles --work-tree $HOME"


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-09-12  2:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 12:33 [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) eliasghafari
2023-03-09 17:12 ` Bart Schaefer
2023-03-09 19:27 ` Oliver Kiddle
2023-03-09 23:54   ` The (e) parameter flag and side-effects Bart Schaefer
2023-03-10 10:07   ` [BUG]Filename autocompletion using git-bare repos (--git-dir=... --work-tree=...) Elias Ghafari
2023-03-10 10:12     ` Roman Perepelitsa
2023-09-11 15:05       ` Elias Ghafari
2023-09-12  2:26         ` Jun T

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).