prezto-inactive-community-fork / prezto

THIS FORK HAS SHUT DOWN – use the original!
https://github.com/sorin-ionescu/prezto
MIT License
115 stars 18 forks source link

Problems with multi user setup and sorin prompt #35

Open donpatrice opened 7 years ago

donpatrice commented 7 years ago

I am using a multi user setup on Ubuntu 16.04 and have the problems mentioned in https://github.com/sorin-ionescu/prezto/issues/1199 even after this commit. Any ideas? Thanks!

paulmelnikow commented 7 years ago

Thanks for reporting the issue.

What is the value of $TMPDIR?

Perhaps the test in 436a7f9 should check ownership (-O) instead of, or in addition to, existence.

donpatrice commented 7 years ago

Sorry, now I am confused. The test was removed with https://github.com/zsh-users/prezto/commit/33923323e1804bbf06269e3916ad2db0f622193d. So TMPDIR is empty, and

$ echo $TMPPREFIX 
/tmp/zsh

for every user and this makes trouble: prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data.

paulmelnikow commented 7 years ago

Huh, you're right. Looks like that was changed in #6. That change makes sense to me though.

Is mktemp -d returning /tmp? That seems broken. This is what I get on my Mac.

❯ mktemp -d
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.KpNG9sPv
❯ mktemp -d
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.OTagTfUI
❯ mktemp -d
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.McdBhifs
❯ mktemp -d
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.mt3fyYFJ
❯ mktemp -d
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.eZ1kEsgJ

This is from a CentOS system:

$ mktemp -d
/tmp/tmp.GUOYd17245
$ mktemp -d
/tmp/tmp.RrArI17248
$ mktemp -d
/tmp/tmp.THmwU17249
$ mktemp -d
/tmp/tmp.RJLRU17268
donpatrice commented 7 years ago

On Ubuntu I get:

$ mktemp -d
/tmp/tmp.lRx1l3MyNf
$ mktemp -d
/tmp/tmp.VuH8Q9EBIR

So this seems okay, but I still get

prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data
paulmelnikow commented 7 years ago

Hmmm. Seems like it should be working then. This is the operative line in the prompt.

Here's what I'm seeing:

~ ❯❯❯ echo $TMPPREFIX
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.YwyQqQ2D/zsh
~ ❯❯❯ echo $_prompt_sorin_precmd_async_data
/var/folders/m2/3rwkhb908xnfvd0059_t24yh0000gq/T/tmp.YwyQqQ2D/zsh-prompt_sorin_data
donpatrice commented 7 years ago

I think I found the problem, but I don't understand it. If I change the login shell to zsh everything is working as expected. But if I have a different shell and then call

zsh

the problem appears.

paulmelnikow commented 7 years ago

Ah! This is from the zsh manpage:

Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

In other words, if your login shell is bash and then you invoke zsh, your .zprofile isn't read! So TMPPREFIX="$(mktemp -d)/zsh" isn't executed.

donpatrice commented 7 years ago

Ah I see. One more thing to understand it better. If I have a bash as login shell and then I call

$ zsh
prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data
$ echo $TMPPREFIX
prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data
$ source .zprofile
prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data
$ echo $TMPPREFIX
/tmp/tmp.BF4fQhzPv5/zsh
prompt_sorin_precmd_async:4: permission denied: /tmp/zsh-prompt_sorin_data

So the prompt plugin does not use the new $TMPPREFIX, does it? So there is no chance of getting it work without zsh as login shell?

Thank you so much.

paulmelnikow commented 7 years ago

Unfortunately it's too late then. TMPPREFIX needs to be set before prompt_sorin_setup runs. e.g.

TMPPREFIX=$(mktemp -d) zsh

I think the right fix is to change Prezto, and move that logic from zprofile into init.zsh (or maybe environment/init.zsh). It's a good out-of-the-box default for any zsh shell, not only a login shell.

Can you check one thing? Is your current shell exporting TMPPREFIX?

❯ env | grep TMPPREFIX
❯

TMPPREFIX is a zsh thing AFAICT, so I would guess your result will be the same as mine.

I would prefer not to clobber that variable if it's already set. Though if bash or your system is setting it to some useless / incorrect value it would be the right thing to do.

donpatrice commented 7 years ago

@paulmelnikow I get the same empty answer:

$ env | grep TMPPREFIX
$

And your workaround with

TMPPREFIX=$(mktemp -d) zsh

works as well. Thank you. I think you are right, it is probably best to fix Prezto and move things.

paulmelnikow commented 7 years ago

There is code in runcoms/zshenv that seems intended to load zprofile at other times. However it only runs when "$SHLVL" -eq 1. zsh started from a bash login shell is probably SHLVL 2.

The SHLVL test was added in sorin-ionescu/prezto#500, prior to which these settings were in zshenv and unconditionally loaded.

paulmelnikow commented 7 years ago

Picking this up at sorin-ionescu/prezto#1199.