views:

1371

answers:

3

When zsh is set as a login shell on Mac OS X, when it is started by iTerm, zsh doesn't consider that it's being run as a login shell, although it's started as ‘-zsh’ (‘-’ is put as the first character of arg[0]) which is supposed to mean that it should start as a login shell.

So, when I set the login shell to bash, bash recognizes this first ‘-’ in $0 and runs as a login shell, but zsh doesn't, although it seems that it should.

Is there a way to either make zsh recognize the ‘-’ in the arg[0], or make iTerm run the shell with a --login command line argument?

+1  A: 

Have you tried editing the shell entry in account settings.

Go to the Accounts preferences, unlock, and right-click on your user account for the Advanced Settings dialog. Your shell should be /bin/zsh, and you can edit that invocation appropriately (i.e. add the --login argument).

Brian Agnew
Unfortunately, that doesn't work: I can set whichever shell I like using chsh (as long as I have this shell listed in /etc/shells), however one cannot add command line arguments to the shell the Advanced preferences dialog (iTerm fails to start the shell up).
ivant
+1  A: 
chsh -s /bin/zsh

You'll be prompted for your password, but once you update your settings any new iTerm/Terminal sessions you start on that machine will default to zsh.

Damien Wilson
Please, read the question first. The problem is not in setting the default shell, the problem is that zsh isn't detecting that it is started as a login shell.
ivant
Ah, my apologies. Have you tried using the -i flag to force zsh to start in interactive mode?
Damien Wilson
A: 

If you want to use oh-my-zsh, the installation for it will make zsh your login shell and start it in interactive mode.

Just follow the directions here.

Here's a snippet from the GitHub page:

  1. Clone the repository

    git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

  2. Create a new zsh config by copying the zsh template we've provided.

    NOTE: If you already have a ~/.zshrc file, you should back it up.

    cp ~/.zshrc ~/.zshrc.orig

    (in case you want to go back to your original settings.)

    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

  3. Set zsh as your default shell:

    chsh -s /bin/zsh

  4. Start / restart zsh (open a new terminal is easy enough...)

Chetan