我不喜欢每次启动终端时都重新输入鱼。我希望Fish默认开启。如何将Fish shell设置为Mac上的默认shell ?


当前回答

Terminal.app →首选项 → 一般→ 贝壳打开,→/垃圾箱/鱼

打开终端,按下命令+,(逗号)。这将打开一个首选项窗口。 第一个标签是“General”。 找到“shell open with”设置,并选择第二个需要shell完整路径的选项。 将链接粘贴到fish命令,通常是/usr/local/bin/fish。

请看这张截图,其中zsh被设置为默认值。

我使用的是macOS v10.12 (Sierra)。它也适用于macOS v10.14 (Mojave)。

其他回答

如何在现代macOS上获得最新版本的Bash(在macOS v10.14 (Mojave)上测试)。

brew install bash
which bash | sudo tee -a /etc/shells
chsh -s $(which bash)

然后你就可以得到vim风格的tab补全了,它只在Bash >= 4上可用(Homebrew的当前版本是5.0.2):

# If there are multiple matches for completion, Tab should cycle through them
bind 'TAB':menu-complete

# Display a list of the matching files
bind "set show-all-if-ambiguous on"

# Perform partial completion on the first Tab press,
# only start cycling full results on the second Tab press
bind "set menu-complete-display-prefix on"

chsh程序将允许您更改默认shell。它需要可执行文件的完整路径,所以如果你的shell是Fish,那么当你输入哪个Fish时,它会希望你提供给定的输出。

您将看到以“Shell:”开头的一行。如果你从未编辑过它,它很可能会显示“Shell: /bin/bash”。将/bin/bash路径替换为所需shell的路径。

1. Sudo nano /etc/shell

2. 将/usr/local/bin/fish添加到shell列表中

3.CHSH -s /usr/local/bin/fish

编辑文件.zshrc并将其更改为

执行 /bin/bash

或者你喜欢什么壳都行。

好处:它不需要root访问权限,可以在所有版本的OS X上运行。

唯一的问题是它不会以这种方式读取文件.bash_profile;只有当Bash作为交互式登录shell运行时,才会读取它。你必须从文件.bashrc中包含它,就像这样:

if [[ "$OSTYPE" == "darwin"* ]]; then
    #local hack on osx.
    if [[ -f $HOME/.bash_profile ]]; then
      . $HOME/.bash_profile
    fi
fi

另外:osx附带的bash版本有点过时,最好使用brew install bash安装一个最新版本的bash;在这种情况下,.zshrc文件应该运行正确的bash版本。目前是

exec /usr/local/Cellar/bash/5.1.8/bin/bash

如果您在使用其他方法时遇到问题,下面的方法可以在macOS v10.14 (Mojave)上工作,但通常应该可以工作。

which fish

将输出路径添加到系统首选项→用户和组→右键单击用户,高级选项。将结果粘贴到“Login shell:”字段中。