sindresorhus / pure

Pretty, minimal and fast ZSH prompt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add pure to prompt themes, connected to MB M1?

christophrumpel opened this issue · comments

General information

I'm using the pure theme now for two years without any issues. Yesterday I switched to a new MacBook Air M1 and now I'm having some issues. I cannot set the prompt to pure with prompt pure.

System report (output of prompt_pure_system_report):

zsh: command not found: prompt_pure_system_report

Other information

I have:

  • Tested with another terminal program and can reproduce the issue: iTerm
  • Followed the integration instructions for my framework

Problem description

When I try to add the theme with prompt pure:

Result:

Usage: prompt <options>
Options:
    -c              Show currently selected theme and parameters
    -l              List currently available prompt themes
    -p [<themes>]   Preview given themes (defaults to all)
    -h [<theme>]    Display help (for given theme)
    -s <theme>      Set and save theme
    <theme>         Switch to new theme immediately (changes not saved)

Use prompt -h <theme> for help on specific themes.

When I show the list of available themes with prompt -l, pure is not in this list.
I have installed it, like the years before, with npm install --global pure-prompt.

I'm not sure what the problem is. Could it be connected to the M1 MacBook?

Reproduction steps

  1. MacBook Air M1
  2. Install pure through npm global
  3. Try to set the theme with the code below from my .zshrc file.

My .zshrc:

# Activate Oh-My-Zsh
source $ZSH/oh-my-zsh.sh

# Change Pure Colors
zmodload zsh/nearcolor
zstyle :prompt:pure:git:branch color green

# Activate Pure Theme
# Make sure to remove this if you use another theme
autoload -U promptinit; promptinit
prompt  pure

What is the output of the npm install? If you're not using zsh from homebrew then automatic linking won't work and there's additional steps to follow, which should've been shown in the npm install output (i.e. adding pure to $fpath).

Hey and thanks @mafredri ,

the output is:

npm install --global pure-prompt  


changed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities

Nothing shown there. It is just strange that it worked the last two years

If you're not using zsh from homebrew then automatic linking won't work...

Isn't oh-my-zsh using zsh? Anything else I can try?

Did you remove pure-prompt before installing? Not sure if running install on an already installed package would produce any new output.

Isn't oh-my-zsh using zsh? Anything else I can try?

We're not associated with oh-my-zsh, not sure why you're mentioning it? You can run which zsh or zsh --version to figure out which one you're using.

I tried removing pure-prompt and installing it again with npm again. The output is still the same. Sry oh-my-zsh was a bit out of context.

which zsh
/opt/homebrew/bin/zsh

I also tried the manual way, like described:

mkdir -p "$HOME/.zsh"
git clone https://github.com/sindresorhus/pure.git "$HOME/.zsh/pure"

# .zshrc
fpath+=$HOME/.zsh/pure

Unfortunately, pure theme still not in the prompt list.

Ok I take the last message, back. Setting it up manually, worked after autoload -U promptinit; promptinit.
So it seems the issue is only connected to the global prompt npm package in my case.

I'm guessing it's the non-standard Homebrew path that's causing it (/opt vs /usr/local). Pure doesn't know the actual path but instead ventures a guess, you can see what it does here:

pure/package.json

Lines 19 to 20 in b83ad6d

"postinstall": "PURE_DEST=/usr/local/share/zsh/site-functions npm run --silent postinstall-link && exit 0; PURE_DEST=\"$PWD/functions\" npm run postinstall-link && npm run postinstall-fail-instructions",
"postinstall-link": "mkdir -p \"$PURE_DEST\" && ln -sf \"$PWD/pure.zsh\" \"$PURE_DEST/prompt_pure_setup\" && ln -sf \"$PWD/async.zsh\" \"$PURE_DEST/async\"",

So I'm pretty sure the reason there's no error is permissions have been modified for /usr/local even though Homebrew isn't installed there. Thus the mkdir doesn't fail and Pure is linked successfully (to /usr/local, which isn't used by your zsh).

Oh you are right, on my other laptop the path is still usr/local/homwbrew. Thanks for the hint.

The path changed on M1 laptops: https://www.reddit.com/r/MacOS/comments/jw9guu/why_did_homebrew_move_from_usrlocalto_opthomebrew/

Do you think this is something your package could check on install?

Same problem here, on MacBook Air M1.

same problem

Ok I take the last message, back. Setting it up manually, worked after autoload -U promptinit; promptinit.
So it seems the issue is only connected to the global prompt npm package in my case.

thanks, it work

Ok I take the last message, back. Setting it up manually, worked after autoload -U promptinit; promptinit.
So it seems the issue is only connected to the global prompt npm package in my case.

thanks, it work

I also tried the manual way, like described:

mkdir -p "$HOME/.zsh"
git clone https://github.com/sindresorhus/pure.git "$HOME/.zsh/pure"

# .zshrc
fpath+=$HOME/.zsh/pure

Thanks!! This works perfectly!

I've gotten so used to pure I can't handle the standard prompt...

Just installed Pure via Homebrew on an M1 iMac and I’m having the same issue. I can work around it, but it would nice if Pure could be updated to handle the new Homebrew paths.

@tobinibot PRs are welcome, but it's not exactly trivial to do it well. We'd have to:

  1. Detect which zsh binary is used by the user (it could be changed via chsh, launched via absolute path, or it might be selected due to path prioritization
  2. Iterate through all fpaths for that binary and see if we have write permission to any of them (however, the user might not appreciate it if the file is linked into any of their own fpaths (personally not a fan of random files appearing in my self-managed folders)
    • Possibly consider doing this for all detected zsh binaries since the user might change default shell.
  3. Due to folder permissions, we still might not succeed and have to fallback to the current approach
  4. The solution also needs to consider non-Darwin platforms

Edit: Then again, we could also just add another hard-coded path like we've done for /usr/local/share/zsh/site-functions, and check both, but I haven't used an M1 nor do I know if that target folder will be writeable. What's the matching path on M1 anyway?

@khaosspawn when you install Pure via npm, it should tell you what to do, i.e. add the fpath to your .zshrc (the actual line is included in the install output).

An alternative is to pure install via Homebrew brew install pure (although I have not tested this).

Thanks @mafredri ! Adding the fpath line was what did the trick.

@mafredri Hmm, yeah, figuring it out the “right way” does seem like a lot of work. I’m not enough of a command-line guru to pull together a PR.

Hard-coding in another path to check could be an interesting option, though.

I’m happy to help in terms of how the directory structure looks now on an M1. What exactly are you looking for, just the new location of the site-functions directory?

Came across the same issue. I noticed that homebrew exposes the following global variables HOMEBREW_REPOSITORY, HOMEBREW_PREFIX and HOMEBREW_SHELLENV_PREFIX and they all return /opt/homebrew for me, I have not looked into the differences much but perhaps this can be utilised in figuring out where to look up the pure install path.

Could someone with an M1 Mac test #606 to see if it works? You can clone the repo and then run npm run postinstall inside it (notice that it should create symlinks in /opt/homebrew/share/zsh/site-functions, so don't let that mess up your setup).

Could someone with an M1 Mac test #606 to see if it works? You can clone the repo and then run npm run postinstall inside it (notice that it should create symlinks in /opt/homebrew/share/zsh/site-functions, so don't let that mess up your setup).

I just tried on an Apple Silicon Mac. I don't have node on my machine yet so I added it manually. I can confirm this is working and will let you know if anything breaks.

Trying this on my new M1Pro and failing during the postinstall-link step with:

ln: /usr/share/zsh/site-functions/propmt_pure_setup: Operation not permitted

Manually adding path to .zshrc works but isn't ideal.

@adamgruber that’s expected when you haven’t installed (or aren’t using) ZSH from Homebrew. We don’t have write permissions to that path. The manual add of fpath is the fix.

I added fpath+=/opt/homebrew/share/zsh/site-functions to the .zshrc (installed via homebrew)

Thank you @diogotorres97, however you missed the "s" in your answer:

# .zshrc

fpath+=/opt/homebrew/share/zsh/site-functions

autoload -U promptinit; promptinit
prompt pure

Now Pure (installed with Homebrew) is working on my MacBook Air M1 with macOS Monterey.

I also tried the manual way, like described:

mkdir -p "$HOME/.zsh"
git clone https://github.com/sindresorhus/pure.git "$HOME/.zsh/pure"

# .zshrc
fpath+=$HOME/.zsh/pure

Thanks!! This works perfectly!

I've gotten so used to pure I can't handle the standard prompt...

If anyone has this issue but is on an intel chip mac, this solution worked for me. I believe the problem is due to running a freshly formatted mac with Monterey, rather than the chip.

I'd also like to point out that another option is to change the Homebrew provided Zsh, FWIW.

brew install zsh
echo /opt/homebrew/bin/zsh | sudo tee -a /etc/shells
chsh -s /opt/homebrew/bin/zsh

Interestingly, I can get Pure working just fine if I source ~/.zshrc which reloads my shell and poof it works.

But when opening new windows Pure never loads, and its not in the prompt -l list and running prompt pure doesn't change anything immediately.

@aaronsmulktis doing source ~/.zshrc doesn't clear the previous environment, so it sounds like things are simply happening in the wrong order. Something that is required for Pure to work happens too soon/late so that it's only available after that next source.

commented

@christophrumpel
read here pure_prompt

image
commented

I'm already success execute

I had a similar kind of issue when installing pure-prompt on TrueNAS Scale (which is running Debian)

- Zsh: zsh 5.9 (x86_64-debian-linux-gnu) (/usr/bin/zsh)
- Operating system: Linux (6.1.74-production+truenas #2 SMP PREEMPT_DYNAMIC Wed Feb 21 20:30:38 UTC 2024 x86_64 GNU/Linux)

Initially I installed pure-prompt using npm install --global pure-prompt.
No errors

prompt pure gave:

Usage: prompt <options>
Options:
-c              Show currently selected theme and parameters
-l              List currently available prompt themes
-p [<themes>]   Preview given themes (defaults to all except current theme)
-h [<theme>]    Display help (for given theme)
-s <theme>      Set and save theme
<theme>         Switch to new theme immediately (changes not saved)

Use prompt -h <theme> for help on specific themes.
% prompt -l
Currently available prompt themes:
adam1 adam2 bart bigfade clint default elite2 elite fade fire off oliver pws redhat restore suse walters zefram

Effectively same issue as above...

Ended up doing git clone into /opt/pure as root and adding fpath+=/opt/pure in .zshrc files.

That worked for me as well (although not ideal).