thoughtbot / laptop

A shell script to set up a macOS laptop for web and mobile development.
https://thoughtbot.com
MIT License
8.5k stars 1.91k forks source link

Updating needs to be run with zsh < #240

Closed allaire closed 10 years ago

allaire commented 10 years ago

I wasn't able to complete a laptop run to update my stuff on OS X Mavericks with my shell set as zsh.

Running: bash <(curl -s https://raw.githubusercontent.com/thoughtbot/laptop/master/mac)

Error is /.oh-my-zsh/oh-my-zsh.sh: line 13: syntax error near unexpected token ('

To fix it, I ran zsh <(curl -s https://raw.githubusercontent.com/thoughtbot/laptop/master/mac)

Since laptop is now idempotent, is this an expected behavior?

allaire commented 10 years ago

Related: https://github.com/thoughtbot/laptop/issues/138

allaire commented 10 years ago

I think the issue is that since I'm running the script on a machine that is already setup with my dotfiles running under zsh, the script try to source my .zshrc file, similar to https://github.com/robbyrussell/oh-my-zsh/issues/2527

I think running the script as bash on a brand new machine, with no dotfiles / zsh specific stuff was fine, but since laptop tries to be idempotent, maybe we need to change the README a bit to run the script with your installed shell?

geoffharcourt commented 10 years ago

I'm having a similar issue, but the failure on OSX when sourcing the .zshrc from thoughtbot's dotfiles is where my error occurs:

Installing watch, to execute a program periodically and show the output ...
Error: watch-0.2.0 already installed

Installing NVM, Node.js, and NPM, for running apps and installing JavaScript packages ...
Error: nvm-0.7.0 already installed
/Users/geoff/.zshrc: line 8: setopt: command not found
failed

I had no problems running laptop on a fresh install of Mavericks, this was only when I re-ran to test idempotency.

allaire commented 10 years ago

@geoffharcourt We have the same issue. The guilty lines are there: https://github.com/thoughtbot/laptop/blob/fdc9ba56c9cd6b0a33cee3c7295f924a302eecd3/mac-components/packages#L36-L41

Since we run the script using bash <(), it looks like the chsh command does not completely switch the shell in the current session, leading bash to fail on some zsh-specific code.

geoffharcourt commented 10 years ago

@allaire yeah, saw the same behavior. Re-running with the pasted command working through zsh over bash allowed me to move forward.

pbrisbin commented 10 years ago

That source command should simply not be there.

When we switched the scripts over from zsh to bash, we had to remove any instance where we sourced ~/.zshrc (it makes no sense to do so in a bash shell), and instead simply made whatever PATH changes we expected the source to do manually. (See the code around rbenv for example).

We need to do that here as well. It was just an oversight that another source ~/.zshrc slipped back in with the recent nvm feature. We should instead modify directly PATH so that nvm can be found.

djcp commented 10 years ago

Yeah, this didn't throw errors on my test osx machine because the .zshrc didn't have any zsh specific stuff in it.

Seems like we could just replace the erroneous source ~/.zshrc with:

source $(brew --prefix nvm)/nvm.sh

and it should work OK. $PATH is not important here, initializing nvm is.

Unfortunately, I don't have an OSX machine with me to test. Can @geoffharcourt or @allaire give it a test (a PR would be great too) and let me know if that fixes everything? If not, I'll look at it tomorrow.

allaire commented 10 years ago

That did it @djcp ! It's also make sense since the if above use the same source syntax, thanks!

I just opened a PR that fix it.

djcp commented 10 years ago

Should be fixed as of PR #241. Thanks!