zsh-workers
 help / color / mirror / code / Atom feed
* Literal `~` directory created?
@ 2023-05-18 13:59 thomas.david.vaughan
  2023-05-18 16:52 ` Phil Pennock
  0 siblings, 1 reply; 7+ messages in thread
From: thomas.david.vaughan @ 2023-05-18 13:59 UTC (permalink / raw)
  To: zsh-workers

I ran `brew bundle install` in a newly created directory which contained only
a Brewfile, and noticed that afterwards a directory named `~` had been
created:

$ ll
total 4
drwx------ 3 tvaughan staff 96 May 18 09:33 '~'
-rw-r--r-- 1 tvaughan staff 14 May 18 09:33  Brewfile

$ find .
.
./Brewfile
./~
./~/.cache
./~/.cache/zsh
./~/.cache/zsh/compcache
./~/.cache/zsh/compcache/brew_all_commands

I have noticed this before perhaps as far back as three months ago, but I
never could narrow it down enough to understand what might be causing this. I
would see this after I ran some homemade scripts I wrote to maintain the
software installed on my laptop. These scripts always ran brew so maybe it's
the culprit?

$ echo $SHELL
/usr/local/bin/zsh

$ which zsh
/usr/local/bin/zsh

$ zsh --version
zsh 5.9 (x86_64-apple-darwin21.3.0)

I run https://github.com/radian-software/radian with no modifications, FYI

Thanks,
-Tom

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

* Re: Literal `~` directory created?
  2023-05-18 13:59 Literal `~` directory created? thomas.david.vaughan
@ 2023-05-18 16:52 ` Phil Pennock
  2023-05-18 17:50   ` Tom Vaughan
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Pennock @ 2023-05-18 16:52 UTC (permalink / raw)
  To: thomas.david.vaughan; +Cc: zsh-workers

On 2023-05-18 at 13:59 +0000, thomas.david.vaughan@gmail.com wrote:
> I ran `brew bundle install` in a newly created directory which contained only
> a Brewfile, and noticed that afterwards a directory named `~` had been
> created:

> I have noticed this before perhaps as far back as three months ago, but I
> never could narrow it down enough to understand what might be causing this. I
> would see this after I ran some homemade scripts I wrote to maintain the
> software installed on my laptop. These scripts always ran brew so maybe it's
> the culprit?

The expansion of `~` is something which the shell does when invoking a
command, but if the command is getting a value from a configuration file
then it needs to be supported on a per-app basis, because then the shell
isn't involved doing some of the work for it.

Similarly, if you have something which wants to use `~` as the default
value for a flag, then that's going to be ... "iffy".

So grep for '~' in your config files and try replacing it with $HOME
instead, see if the command does env-var expansion or if you end up with
a directory named '$HOME' in your home-dir.  :^)

There's nothing zsh-specific or zsh-involved here: the problem is
arising _because the shell is not being involved_.

-Phil


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

* Re: Literal `~` directory created?
  2023-05-18 16:52 ` Phil Pennock
@ 2023-05-18 17:50   ` Tom Vaughan
  2023-05-18 17:59     ` Phil Pennock
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Vaughan @ 2023-05-18 17:50 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-workers



> On May 18, 2023, at 12:52, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> 
> On 2023-05-18 at 13:59 +0000, thomas.david.vaughan@gmail.com wrote:
>> I ran `brew bundle install` in a newly created directory which contained only
>> a Brewfile, and noticed that afterwards a directory named `~` had been
>> created:
> 
>> I have noticed this before perhaps as far back as three months ago, but I
>> never could narrow it down enough to understand what might be causing this. I
>> would see this after I ran some homemade scripts I wrote to maintain the
>> software installed on my laptop. These scripts always ran brew so maybe it's
>> the culprit?
> 
> The expansion of `~` is something which the shell does when invoking a
> command, but if the command is getting a value from a configuration file
> then it needs to be supported on a per-app basis, because then the shell
> isn't involved doing some of the work for it.
> 
> Similarly, if you have something which wants to use `~` as the default
> value for a flag, then that's going to be ... "iffy".
> 
> So grep for '~' in your config files and try replacing it with $HOME
> instead, see if the command does env-var expansion or if you end up with
> a directory named '$HOME' in your home-dir.  :^)
> 
> There's nothing zsh-specific or zsh-involved here: the problem is
> arising _because the shell is not being involved_.

Thanks, Phil. Based on this it seems like the problem is due to:

    mkdir -m 0700 -p "$_cache_dir"

at https://github.com/zsh-users/zsh/blob/master/Completion/Base/Utility/_store_cache#L19

Tilde is not expanded when quoted, right? _cache_dir is set a little higher up at https://github.com/zsh-users/zsh/blob/master/Completion/Base/Utility/_store_cache#L10:

    $ echo $_cache_dir

    $ zstyle -s ":completion:${curcontext}:" cache-path _cache_dir

    $ echo $_cache_dir
    ~/.cache/zsh/compcache

Perhaps this tilde should be expanded? Running the mkdir command above creates a literal '~' directory in the current working directory.

-Tom



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

* Re: Literal `~` directory created?
  2023-05-18 17:50   ` Tom Vaughan
@ 2023-05-18 17:59     ` Phil Pennock
  2023-05-18 18:48       ` Tom Vaughan
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Pennock @ 2023-05-18 17:59 UTC (permalink / raw)
  To: zsh-workers

On 2023-05-18 at 13:50 -0400, Tom Vaughan wrote:
> Thanks, Phil. Based on this it seems like the problem is due to:
> 
>     mkdir -m 0700 -p "$_cache_dir"

> Tilde is not expanded when quoted, right? _cache_dir is set a little higher up at https://github.com/zsh-users/zsh/blob/master/Completion/Base/Utility/_store_cache#L10:
> 
>     $ echo $_cache_dir
> 
>     $ zstyle -s ":completion:${curcontext}:" cache-path _cache_dir
> 
>     $ echo $_cache_dir
>     ~/.cache/zsh/compcache
> 
> Perhaps this tilde should be expanded? Running the mkdir command above creates a literal '~' directory in the current working directory.

It should have been expanded _when you set the style_.

So don't quote a parameter when invoking zstyle to set it, because then
you're setting the style's value to hold the literal string.

You should have things like:

    zstyle ':completion:*' urls ~/.urls
    zstyle ':completion:*' cache-path ~/.cache/zsh/${HOST%%.*}

-Phil


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

* Re: Literal `~` directory created?
  2023-05-18 17:59     ` Phil Pennock
@ 2023-05-18 18:48       ` Tom Vaughan
  2023-05-18 21:37         ` Phil Pennock
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Vaughan @ 2023-05-18 18:48 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-workers



> On May 18, 2023, at 13:59, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> 
> On 2023-05-18 at 13:50 -0400, Tom Vaughan wrote:
>> Thanks, Phil. Based on this it seems like the problem is due to:
>> 
>>    mkdir -m 0700 -p "$_cache_dir"
> 
>> Tilde is not expanded when quoted, right? _cache_dir is set a little higher up at https://github.com/zsh-users/zsh/blob/master/Completion/Base/Utility/_store_cache#L10:
>> 
>>    $ echo $_cache_dir
>> 
>>    $ zstyle -s ":completion:${curcontext}:" cache-path _cache_dir
>> 
>>    $ echo $_cache_dir
>>    ~/.cache/zsh/compcache
>> 
>> Perhaps this tilde should be expanded? Running the mkdir command above creates a literal '~' directory in the current working directory.
> 
> It should have been expanded _when you set the style_.
> 
> So don't quote a parameter when invoking zstyle to set it, because then
> you're setting the style's value to hold the literal string.
> 
> You should have things like:
> 
>    zstyle ':completion:*' urls ~/.urls
>    zstyle ':completion:*' cache-path ~/.cache/zsh/${HOST%%.*}

Sorry, I'm a bit confused. The previous link is to the zsh source code mirror on GitHub, specifically the definition for _store_cache which is what calls zstyle and mkdir. 

Do you mean that, in this particular case, radian should include these two zstyle commands above in its setup? But if zsh provides a fallback, is this really a requirement?

FYI - I left out that I traced brew, which calls _store_cache at  https://github.com/Homebrew/brew/blob/16b2a14c9408140b04828462b660d30056421fdb/Library/Homebrew/completions/zsh.erb#L143

-Tom



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

* Re: Literal `~` directory created?
  2023-05-18 18:48       ` Tom Vaughan
@ 2023-05-18 21:37         ` Phil Pennock
  2023-05-18 22:25           ` Tom Vaughan
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Pennock @ 2023-05-18 21:37 UTC (permalink / raw)
  To: Tom Vaughan; +Cc: zsh-workers

On 2023-05-18 at 14:48 -0400, Tom Vaughan wrote:
> > On May 18, 2023, at 13:59, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> > You should have things like:
> > 
> >    zstyle ':completion:*' urls ~/.urls
> >    zstyle ':completion:*' cache-path ~/.cache/zsh/${HOST%%.*}
> 
> Sorry, I'm a bit confused. The previous link is to the zsh source code mirror on GitHub, specifically the definition for _store_cache which is what calls zstyle and mkdir. 

zstyle is used in two ways:

 1. To set a style
 2. To query a style

The _store_cache function queries the style:

    zstyle -s ":completion:${curcontext}:" cache-path _cache_dir
    : ${_cache_dir:=${ZDOTDIR:-$HOME}/.zcompcache}

This is a lookup, for a string (-s); see zshmodules(1) for the
documentation.  Then it supplies a default to use if that resulted in an
empty string (`:`/`true` command, invoked for side-effect of argv
evaluations, and ${param:=default} assignment to populate the variable).

So this does not put a '~' into the cache-path.  Something else has put
that tilde in there.

The _setting_ of the zstyle is done either with nothing between the
`zstyle` and the pattern, or a `-e` for deferred evaluation.  Or a '-'
or '--', pedantically.  The doc entry is:

    zstyle [ - | -- | -e ] pattern style string ...

Somewhere, something in startup files or otherwise is populating some
style settings with a literal tilde in there.

Run:

    zstyle -L | grep '~'

for a first approximation (might include other tildes) of which entries
might have issues.

Try this, to find likely candidates:

    grep "zstyle.*'~" ${ZDOTDIR:-$HOME}/.z*

Now, should zsh have more guards against common misuse like this?
Perhaps, but it's likely to be a quixotic quest.


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

* Re: Literal `~` directory created?
  2023-05-18 21:37         ` Phil Pennock
@ 2023-05-18 22:25           ` Tom Vaughan
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Vaughan @ 2023-05-18 22:25 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-workers



> On May 18, 2023, at 17:37, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> 
> Somewhere, something in startup files or otherwise is populating some
> style settings with a literal tilde in there.

Found it: https://github.com/marlonrichert/zsh-autocomplete/commit/cc831ed665c8a608079184301fd7b927eb4fbfbd

TIL `zinit update`

$ echo $_cache_dir

$ zstyle -s ":completion:${curcontext}:" cache-path _cache_dir

$ echo $_cache_dir
/Users/tvaughan/.cache/zsh/compcache

Thanks, Phil




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

end of thread, other threads:[~2023-05-18 22:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-18 13:59 Literal `~` directory created? thomas.david.vaughan
2023-05-18 16:52 ` Phil Pennock
2023-05-18 17:50   ` Tom Vaughan
2023-05-18 17:59     ` Phil Pennock
2023-05-18 18:48       ` Tom Vaughan
2023-05-18 21:37         ` Phil Pennock
2023-05-18 22:25           ` Tom Vaughan

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).