How can I reset the startup directory to my HOME in Fish?

こ雲淡風輕ζ 提交于 2020-01-14 10:20:08

问题


In my desktop manager, I have bound fish to a keyboard shortcut Ctrl + ~. On startup, fish opens the directory /usr/lib/lightdm/lightdm. This is quite annoying, because I have no business with lightdm, and I usually work on code in my $HOME directory.

How can I change the directory that fish starts in? I would like to change the startup directory simply to ~/


回答1:


I had found that the config.fish file that runs at startup had been changing my default working directory.

A misguided attempt at setting my PATH left a list of directories in my config.fish, the first of which was /usr/lib/lightdm/lightdm. Fish automatically assumes directories without a command should be cd`d into, so my shell was cd`ing into that directory at startup.

I removed the stray lines and all is well.

To change your fish startup directory: add cd /path/to/new/startup/directory to your ~/.config/fish/config.fish file, or create it if it does not exist.




回答2:


As @nathaniel-waisbrot says in this answer, you can cd only when running fish interactively (the shell not the scripts):

# ~/.config/fish/config.fish

if status is-interactive
  cd $HOME
end

Using fish's status command

If that doesn't do it for you, it might be your fish theme. I use the dangerous theme which has a bookmarking feature. Removing the bookmark from my startup directory solved this problem for me.



来源:https://stackoverflow.com/questions/16000622/how-can-i-reset-the-startup-directory-to-my-home-in-fish

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!