macos 如何在 Mac 上设置我的默认 shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/453236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:00:42  来源:igfitidea点击:

How to set my default shell on Mac?

macosterminalfish

提问by Léo Léopold Hertz ??

I do not like to retype fish every time I start terminal. I want fishon by default. How can I set fish shell as my default shell on a Mac?

我不喜欢每次启动终端时都重新输入鱼。我想要fish默认。如何将鱼壳设置为 Mac 上的默认壳?

采纳答案by Tushar Vazirani

These are applicable to MacOS Sierra 10.12.5 (16F73) and probably some other recent and upcoming versions of MacOS.

这些适用于 MacOS Sierra 10.12.5 (16F73) 以及其他一些近期和即将推出的 MacOS 版本。

  1. chshis not enough to change the default shell. Make sure you press Command+,while your terminal is open and change the 'Shells open with' option to 'Default login shell.'

  2. In case of bash, make sure that you execute echo $BASH_VERSIONto confirm you are running the intended version of bash. bash --versiondoes not give you correct information.

  1. chsh改变默认外壳是不够的。确保在终端打开时按Command+,并将“外壳打开方式”选项更改为“默认登录外壳”。

  2. 如果是 bash,请确保您执行echo $BASH_VERSION以确认您正在运行预期版本的 bash。bash --version没有给你正确的信息。

回答by user391339

1. sudo nano /etc/shellsenter image description here

1. 须藤纳米 /etc/shells在此处输入图片说明

2. add /usr/local/bin/fish to your list of shellsenter image description here

2. 将 /usr/local/bin/fish 添加到您的 shell 列表中在此处输入图片说明

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

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

回答by Aif

You can use chshto change a user's shell.

您可以使用chsh来更改用户的外壳。

Run the following code, for instance, to change your shell to Zsh

例如,运行以下代码,将 shell 更改为 Zsh

chsh -s /bin/zsh

As described in the manpage, and by Lorin, if the shell is not known by the OS, you have to add it to its known list: /etc/shells.

如联机帮助页和 Lorin 所述,如果操作系统不知道该 shell,则必须将其添加到其已知列表中:/etc/shells.

回答by Paolo Moretti

From Terminal:

从终端:

  1. Add Fish to /etc/shells, which will require an administrative password:

    sudo echo /usr/local/bin/fish >> /etc/shells
    
  2. Make Fish your default shell with chsh:

    chsh -s /usr/local/bin/fish
    
  1. 将 Fish 添加到/etc/shells,这将需要管理密码:

    sudo echo /usr/local/bin/fish >> /etc/shells
    
  2. 使用以下命令将 Fish 设为默认 shell chsh

    chsh -s /usr/local/bin/fish
    


From System Preferences:

从系统偏好设置:

  1. User and Groups → ctrl-click on Current User → Advanced Options...

  2. Change Login shell to /usr/local/bin/fish

    login shell

  3. Press OK, log out and in again

  1. 用户和组 → ctrl-单击当前用户 → 高级选项...

  2. 将登录外壳更改为 /usr/local/bin/fish

    登录外壳

  3. 按确定,退出并重新登录

回答by Lorin Hochstein

Here's another way to do it:

这是另一种方法:

Assuming you installed it with MacPorts, which can be done by doing:

假设您使用 MacPorts 安装它,可以通过以下方式完成:

sudo port install fish

Your shell will be located in /opt/local/bin/fish.

您的外壳将位于/opt/local/bin/fish.

You need to tell OSX that this is a valid shell. To do that, add this path to the end of the /etc/shellsfile.

您需要告诉 OSX 这是一个有效的 shell。为此,请将此路径添加到/etc/shells文件末尾。

Once you've done this, you can change the shell by going to System Preferences -> Accounts. Click on the Lock to allow changes. Right-click on the account, and choose "Advanced Options...". In the "Login shell" field, add the path to fish.

完成此操作后,您可以通过转到“系统偏好设置”->“帐户”来更改外壳。单击锁定以允许更改。右键单击该帐户,然后选择“高级选项...”。在“登录shell”字段中,添加fish 的路径。

回答by quaintm

The only thing that worked for me was a combination of all these methods.

唯一对我有用的是所有这些方法的组合。

  1. First I had to add fish to the /etc/shellsfile

  2. Then I ran chsh -s /usr/local/bin/fish

  3. Finally, I typed Command+,and added /usr/local/bin/fishto the default path there

  1. 首先,我必须将鱼添加到/etc/shells文件中

  2. 然后我跑了 chsh -s /usr/local/bin/fish

  3. 最后,我输入Command+,并添加/usr/local/bin/fish到那里的默认路径

Only after I had done all three things did fish start popping up as the default for new terminal windows.

只有在我完成所有三件事之后,fish 才开始作为新终端窗口的默认值弹出。

回答by MagicDude4Eva

On macOS Mojave I had to do the following (using zsh as an example):

在 macOS Mojave 上,我必须执行以下操作(以 zsh 为例):

brew install zsh
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)

回答by Pankaj

Terminal.app> Preferences> General> Shells open with:> /bin/fish

Terminal.app> Preferences> General> Shells open with:>/bin/fish

  1. Open your terminal and press command+,(comma). This will open a preferences window.
  2. The first tab is 'General'.
  3. Find 'Shells open with' setting and choose 2nd option which needs complete path to the shell.
  4. Paste the link to your fish command, which generally is /usr/local/bin/fish.
  1. 打开终端并按command+ ,(逗号)。这将打开一个首选项窗口。
  2. 第一个选项卡是“常规”。
  3. 找到“Shells open with”设置并选择需要完整路径的第二个选项。
  4. 将链接粘贴到您的 fish 命令,通常是/usr/local/bin/fish.

See this screenshot where zshis being set as default.

请参阅此屏幕截图,其中zsh设置为默认值。

screenshot of entering <code>/bin/zsh</code>in Terminal.app preferences

screenshot of entering <code>/bin/zsh</code>in Terminal.app preferences

I am using macOS Sierra. Also works in macOS Mojave.

我正在使用macOS Sierra。也适用于macOS Mojave

回答by Bruno Bronosky

How to get the latest version of bash on modern macOS (tested on Mojave).

如何在现代 macOS 上获取最新版本的 bash(在 Mojave 上测试)。

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

Then you are ready to get vim style tab completionwhich is only available on bash>=4 (current version in brewis 5.0.2

然后你就可以得到 vim 风格的 tab 补全了,它只在 bash>=4 上可用(当前版本brew是 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"