Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
christophrumpel opened this issue Feb 9, 2021 · 31 comments · Fixed by #606
Closed
2 tasks done

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

christophrumpel opened this issue Feb 9, 2021 · 31 comments · Fixed by #606

Comments

@christophrumpel
Copy link

christophrumpel commented Feb 9, 2021

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
@mafredri
Copy link
Collaborator

mafredri commented Feb 9, 2021

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

@christophrumpel
Copy link
Author

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?

@mafredri
Copy link
Collaborator

mafredri commented Feb 9, 2021

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.

@christophrumpel
Copy link
Author

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

@christophrumpel
Copy link
Author

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.

@christophrumpel
Copy link
Author

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.

@mafredri
Copy link
Collaborator

mafredri commented Feb 9, 2021

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

@christophrumpel
Copy link
Author

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?

@erusev
Copy link

erusev commented Feb 21, 2021

Same problem here, on MacBook Air M1.

@loyio
Copy link

loyio commented Mar 6, 2021

same problem

@loyio
Copy link

loyio commented Mar 6, 2021

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

1 similar comment
@hermitcai
Copy link

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

@n13
Copy link

n13 commented May 13, 2021

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

@tobinibot
Copy link

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.

@mafredri
Copy link
Collaborator

mafredri commented Jun 16, 2021

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

@khaosspawn
Copy link

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

@tobinibot
Copy link

@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?

chriseverson added a commit to chriseverson/dotfiles that referenced this issue Jun 23, 2021
chriseverson added a commit to chriseverson/dotfiles that referenced this issue Jun 23, 2021
@antonk52
Copy link

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.

mafredri added a commit that referenced this issue Aug 28, 2021
On M1 Macs, the Homebrew path has changed to `/opt/homebrew` so we check
at which path zsh is present.

Additionally we try to install into standard unix path if present,
however, this will likely only help people installing via `sudo`.

Finally, the error text has been updated to prioritize updating `.zshrc`
instead of doing a manual install.

Fixes #584.
@mafredri
Copy link
Collaborator

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

@Zehua-Chen
Copy link

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.

conradbeach added a commit to conradbeach/dotfiles that referenced this issue Nov 3, 2021
I was having issues (along with others [1]) getting Pure Prompt to work
correctly on an M1 Mac when I installed it with NPM or Homebrew.
Installing manually (though a little less elegant) gets things working.

[1]: sindresorhus/pure#584
@adamgruber
Copy link

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.

@mafredri
Copy link
Collaborator

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

@diogotorres97
Copy link

diogotorres97 commented Dec 8, 2021

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

@darciovilela
Copy link

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.

@virsaviya
Copy link

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.

@mafredri
Copy link
Collaborator

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

@aaronsmulktis
Copy link

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.

@mafredri
Copy link
Collaborator

mafredri commented Oct 9, 2022

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

@huanglian666
Copy link

@christophrumpel
read here pure_prompt

image

@huanglian666
Copy link

I'm already success execute

kallgren added a commit to kallgren/dotfiles that referenced this issue Oct 25, 2023
@pommetjehorlepiep
Copy link

pommetjehorlepiep commented Mar 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.