I'm running Fish on a Vagrant-controlled VM. I want to use ~vagrant
as the place where VM-specific configuration gets dumped, so that's my $HOME
. I have /vagrant
as a directory shared with the host, and that's where I want to be all the time.
When I log in to the VM, I'd like Fish to dump me into /vagrant/
.
In Bash, I'd do this by putting cd /vagrant/
into ~/.bashrc
. However, I see there's another question about changing directories in Fish and the comments suggest that putting cd /vagrant/
into ~/.config/fish/config.fish
would be a mistake because Fish will implicitly evaluate it on every command. (I didn't add to that question, because it appears to be about fixing a bugged user environment to start in the standard directory, when I want the other way around.)
Can someone clarify the best way to make Fish start the user in a non-HOME
directory?
I assume you're referring to this comment in the question you liked to:
No, don't do it! If you add a cd to your config.fish, it will work for
everyday use, but fish will also run the cd before you run any Fish
shell script.
And that is true as far as it goes. The config.fish script is read by every fish process regardless of whether or not it is interactive. The way to deal with that is to only do the cd if the shell is interactive:
if status is-interactive
cd /vagrant
end
Note that you may need to use status -i
if you're running an old version.
Also, in case it isn't obvious, this doesn't actually change $HOME
and thus does not change where fish looks for your personal autoloaded functions or where it stores its command history. So if you want to "use ~vagrant as the place where VM-specific configuration gets dumped" you need to actually change your home directory. Alternatively, in addition to executing the cd
command also set HOME
.