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

Scripting with zplug: `zsh -c "source ~/.zshrc"` fails when running `zplug load` #209

Closed
kevinjalbert opened this issue Jul 2, 2016 · 10 comments

Comments

Projects
None yet
4 participants
@kevinjalbert
Copy link

commented Jul 2, 2016

Problem Summary

It simply seems that zplug does not work in a script setting. I saw #116 but I'm not to sure this is related, and it was closed due to inactivity. I do want to mention that this process worked with zgen, so it appears to be something specific to zplug.

System Information

  • uname -a

    Darwin katana 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
    
  • zsh version

    zsh 5.2 (x86_64-apple-darwin14.5.0)
    
  • zplug version/commit

    2.1.0 (master -- d49d056)
    

Minimal zshrc

Simply sourcing zplug and installing a single plugin k. Echoing at ending of file to show that file was executed fully.

source ~/.zplug/init.zsh
zplug "supercrabtree/k"
zplug check || zplug install
zplug load --verbose
echo "finished .zshrc"

Steps to Reproduce

  1. k should show the ls content of the current directory (essentially showing that the k command from the plugin works)
  2. zsh -c 'k' -- I didn't expect this to work as the zsh -c does not source the ~/.zshrc as its not an interactive shell
  3. zsh -c 'source ~/.zshrc; k' -- I figure this would work, but it does does not output anything (not even the echo in sourced ~/.zshrc)
  4. Comment out the zplug load --verbose and the echo will now be printed
@NigoroJr

This comment has been minimized.

Copy link
Member

commented Jul 5, 2016

Thanks for reporting! I'm not sure if I followed the right steps, but I couldn't reproduce it. Here's what I did:

  1. Create an empty .zshrc.
  2. Create ~/issue_209.zsh with the exact same content as what you described.
  3. Start a new zsh session.
  4. Run zsh -c 'source ~/issue_209.zsh; k' (I assumed running k in the current shell is a typo)

And got the output finished .zshrc as well as the output from k. I'm on OSX 10.9.5. Please let me know if you notice I'm doing something wrong.

@dezza

This comment has been minimized.

Copy link

commented Jul 5, 2016

@kevinjalbert could you try without your dotfiles enabled (or comment out the line that loads them) ?

I use that plugin too and have no problem.

If you did a bootstrap script script maybe you forgot a #!/usr/bin/env zsh shebang and hence the script runs as default shell /bin/sh ?

zsh script.zsh runs with zsh

./script.zsh does not unless it has the line #!/usr/bin/env zsh. Even though it has the .zsh extension.

@kevinjalbert

This comment has been minimized.

Copy link
Author

commented Jul 6, 2016

@NigoroJr Good call on the typo with running k in the current shell (fixed that up).

I saw the same results by following the steps you outlined. I fiddled around and found that the issue is that you have an empty .zshrc while in my situation the .zshrc is the minimal setup (i.e., the content you have in ~/issue_209.zsh. It seems that if you are to run zsh -c 'source ~/issue_209.zsh; k' twice. When using your setup the first one works, then the second invocation fails.

This led me to thinking that this is a cache problem. Now between runs I cleared the cache (rm -f ~/.zplug/.cache) and the next invocation works!

I'm not too sure but it seems that when using zsh -c "..." if zplug load the cache or writes to the cache something happens that causes the remaining bit of the file to not execute (everything after the zplug load from what I've seen).


@dezza I was using the minimal zsh config (and now just tried with an empty .zshrc). I don't think anything else is loading up (as I also have empty .zlogin and .zshenv).

@NigoroJr

This comment has been minimized.

Copy link
Member

commented Jul 15, 2016

Sorry, I've been caught up recently but I'll make sure to check it out when I get the time! @kevinjalbert Thanks for the follow up about the cache 👍

@b4b4r07

This comment has been minimized.

Copy link
Member

commented Jul 20, 2016

@kevinjalbert Sorry! I’ve been tied up with work and I cannot catch up this issue. Say frankly, what do you want to do?

@kevinjalbert

This comment has been minimized.

Copy link
Author

commented Jul 20, 2016

@b4b4r07 no worries about not being able to get to this right away. For the time being I've found a temporary solution:

if [[ -o interactive ]] then
  zplug load
fi

With this in my .zshrc the zsh -c "..." will not re-execute that zplug load command again.


I think there is still value in this issue but it is a pretty specific case. There is also a temporary solution to the issue. Possibly keep the issue open but de-prioritize it?

@b4b4r07

This comment has been minimized.

Copy link
Member

commented Jul 22, 2016

Thanks. Hmm, it is true that this I think case is a pretty specific. What do @NigoroJr think? I don't grasp this as a big problem.

By the way, how can you write in zgen?

@NigoroJr

This comment has been minimized.

Copy link
Member

commented Aug 2, 2016

Sorry it took me long to get back to this issue. It turns out that the culprit of zplug not loading in non-interactive shells was this line. I'm not sure what side effects there are to naively removing this line, but now we know why it happens.

kevinjalbert added a commit to kevinjalbert/dotfiles that referenced this issue Sep 17, 2016

@NigoroJr

This comment has been minimized.

Copy link
Member

commented Sep 25, 2016

@kevinjalbert Could you try the fix-209 branch and see if it fixes this problem?

@kevinjalbert

This comment has been minimized.

Copy link
Author

commented Oct 2, 2016

Sorry for taking my time in testing this out. Seems like it worked when I tried using the fix-209 branch. 👍

@NigoroJr NigoroJr closed this in b1521a3 Oct 8, 2016

kevinjalbert added a commit to kevinjalbert/dotfiles that referenced this issue Jan 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.