Also, I should mention that every time I spin up a new shell in iTerm - including new tabs, or even new panes in tmux, it seems to default back to bash now - quite annoying.
I was literally about to file an issue about this (and will in a second). There are a couple of things that can go wrong here, so can you post a copy of your ~/.config/fish/config.fish, ~/.rc, ~/.bashrc, ~/.profile, ~/.bash_profile (any of those that exist) and the output of env?
Yup, I found that as well - I think I've managed to sort of fix things by changing "Login shell" to "Command", and also by setting the following in my ~/.tmux.conf:
set -g default-command /usr/local/bin/fish
However, I'm still curious as to what's going on, or why chsh has suddenly stopped working.
Note that the automatic command to install shell integration installed the bash version (even though chsh should have been set to chsh before), so I had to manually download and add the fish iTerm integration script.
Yeah, it's definitely a bug, and since I didn't get around to opening a separate issue for it yet, I'll detail it here: chsh on a "traditional" system edits an entry in a plaintext conf file, typically /etc/passwd. But on modern OS X (not sure since when) its kept as an attribute in OpenDirectory:
dscl . read /Users/$USER UserShell'
Terminal correctly uses this value; for some reason, present iTerm builds, it stays as /bin/bash regardless. @gnachman?
@victorhooi Also, I actually recommend one not use chsh, particularly with fish, or any shell that you'd need to edit /etc/shells to use. For instance what happens if your /usr/local/bin/fish gets a bad update from homebrew, or is otherwise corrupted or blown away? You're left without any shell at all (and this is when you'll really want that "Command:" option in iTerm or Terminal.app).
Instead,
set up all your environmental variables in .rc
put [ -e ~/.rc ] && . ~/.rc in .profile and .bashrc
put [ -e ~/.bashrc ] && . ~/.bashrc || [ -e ~/.rc ] && . ~/.rc in .bash_profile
then end your .bash_profile with the line
which fish >/dev/null 2>&1 && exec fish -il
This way:
your environment stays the same, whether your in sh, bash, or fish
you don't have to duplicate your env setup in ~/config/fish/config.fish
it doesn't hardcode the path to fish, so it works even if its moved
and even if fish gets deleted, you'll fall back to bash.
And of course, this also works for regular users who can't edit /etc/shells, which is probably the boat we'll all be in once were "rootless" in 10.11.
iTerm2 uses the $SHELL environment variable it was started with when you choose Login Shell. I need to change it to use directory services, obviously. I'm not sure why it would have changed on you, but does restarting iTerm2 help?
Nope. I've noticed this for some time actually. I honestly don't know when it started. Possibly since 10.10... But because I use the method above, it never bothered me enough to do anything about it.
I wonder how this variable gets set in the first place? Like, where does _NSGetEnviron() get its information from?
Also, this seems to be recent, as I'm fairly sure I didn't have this issue before - possibly either with OSX 10.11, or with a recent nightly build of iTerm. Did something change?
I downloaded your build, can confirm that appears to fix the issue - I set iTerm's Command back to "Login shell", and removed the default-command line in .tmux.conf, and fish shell is now correctly started up both for iTerm, and in tmux.
Will this be in the next nightly? =)
Finally, this is for my own learning - how is the $SHELL variable actually set? As in, is it defined somewhere, or does iTerm/Terminal set it somehow? I'm a bit confused, because OSX's inbuilt terminal and iTerm seem to have different $SHELL variables (Terminal had fish, and iTerm has bash).
@geoff-codes Interesting, about not using chsh. I confess I don't know much about the background here - I was basically going off what brew info fish says:
You will need to add: #{HOMEBREW_PREFIX}/bin/fish to /etc/shells. Run: chsh -s #{HOMEBREW_PREFIX}/bin/fish to make fish your default shell.
@victorhooi Yeah, I've tried to get them to change that. It's really not so good an idea; again, if there's a bad commit made to fish.rb and you brew upgrade, you're hosed.
@gnachman This looks like an Apple bug feature to me. If you do shell script "env" in Script Editor, it also always shows SHELL=/bin/bash.
@victorhooi This change will be in the next nightly build.
@geoff-codes $SHELL is set by some mysterious system process, but it generally is correct. This is the first I've heard of us launching the wrong shell for a user.
I can tell you that on my systems $SHELL is /bin/tcsh when iTerm2 is launched. I wouldn't trust the output of "shell script 'env'" because shell scripts are generally run within bash implicitly.
I can tell you that on my systems $SHELL is /bin/tcsh when iTerm2 is launched.
@gnachman So... have you been upgrading the same user account since 10.2? Or set it that way?
Definitely not! I think $SHELL is set correctly for most users, or I'd have heard about it by now, since iTerm2 used it to launch the proper shell for users whose profile was set to "Login shell" but were not launching into their home directory.