如何在 Mac 上设置默认 shell,例如 Fish?

发布于 2024-07-11 07:05:44 字数 2015 浏览 11 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

一笑百媚生 2024-07-18 07:05:44

1. sudo nano /etc/shells
在此处输入图像描述

2. 将 /usr/local/bin/fish 添加到您的 shell 列表
在此处输入图像描述

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

1. sudo nano /etc/shells
enter image description here

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

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

妖妓 2024-07-18 07:05:44

从终端:

  1. 将 Fish 添加到 /etc/shells,这将需要管理密码:

    sudo echo /usr/local/bin/fish >>>   /etc/shell 
      
  2. 使用 chsh 将 Fish 设置为默认 shell:

    chsh -s /usr/local/bin/fish 
      

从系统偏好设置:

  1. 用户和组 → 按住 Ctrl 键单击当前用户 → 高级选项...

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

    登录 shell

  3. 按确定,注销并重新登录

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
    

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

罗罗贝儿 2024-07-18 07:05:44

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

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

chsh -s /bin/zsh

正如 Lorin 的联机帮助页中所述,如果操作系统不识别该 shell,则必须将其添加到其已知列表中: /etc/外壳

You can use chsh to change a user's shell.

Run the following code, for instance, to change your shell to 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.

空城旧梦 2024-07-18 07:05:44

这些适用于 macOS v10.12.5 (Sierra) (16F73) 以及可能其他一些最近和即将推出的 macOS 版本。

  1. chsh 不足以更改默认 shell。 确保在终端打开时按 Command + ,,并将“Shells 打开方式”选项更改为“默认登录 shell”。

  2. 如果是 Bash,请确保执行 echo $BASH_VERSION 以确认您正在运行所需版本的 Bash。 bash --version 没有为您提供正确的信息。

These are applicable to macOS v10.12.5 (Sierra) (16F73) and probably some other recent and upcoming versions of macOS.

  1. chsh is 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_VERSION to confirm you are running the intended version of Bash. bash --version does not give you correct information.

后eg是否自 2024-07-18 07:05:44

这是另一种方法:

假设您使用 MacPorts 安装它,这可以通过执行:

sudo port install fish

您的 shell 将位于 /opt/local/bin/fish 中。

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

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

Here's another way to do it:

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

sudo port install fish

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

You need to tell OS X that this is a valid shell. To do that, add this path to the end of the /etc/shells file.

Once you've done this, you can change the shell by going to System PreferencesAccounts. 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.

杯别 2024-07-18 07:05:44
  • 输入fish检查是否安装正确,如果安装正确,输入exit
  • 输入whichfish,复制路径。
  • 输入 sudo sh -c 'echo>>> /etc/shells'
  • 重新启动终端,
  • 输入 chsh -s
  • 再次重新启动终端,
  • 现在应该可以工作了。
  • type fish to check if it was installed correctly, if installed correctly, type exit
  • type which fish, copy the path.
  • type sudo sh -c 'echo <your-fish-path-here> >> /etc/shells'
  • restart your terminal
  • type chsh -s <your-fish-path-here>
  • restart terminal again
  • it should work now.
握住你手 2024-07-18 07:05:44

Terminal.app首选项常规Shells open with/bin/fish >

  1. 打开终端并按 command + ,(逗号)。 这将打开一个首选项窗口。
  2. 第一个选项卡是“常规”。
  3. 找到“Shells open with”设置并选择需要 shell 完整路径的第二个选项。
  4. 将链接粘贴到 Fish 命令,通常为 /usr/local/bin/fish

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

截图在 Terminal.app 首选项中输入 /bin/zsh

我正在使用 macOS v10.12< /a>(塞拉利昂)。 它也适用于 macOS v10.14 (Mojave)。

Terminal.appPreferencesGeneralShells 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 the second option which needs complete path to the shell.
  4. Paste the link to your fish command, which generally is /usr/local/bin/fish.

See this screenshot where zsh is being set as default.

Screenshot of entering /bin/zsh in Terminal.app preferences

I am using macOS v10.12 (Sierra). It also works in macOS v10.14 (Mojave).

感情旳空白 2024-07-18 07:05:44

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

  1. 首先,我必须将 Fish 可执行文件的路径添加到 /etc/shells 文件

  2. 然后我运行 chsh -s /usr/local/bin/fish< /p>

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

只有在我完成所有三个操作之后Fish 开始作为新终端窗口的默认值弹出。

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

  1. First I had to add the path to the Fish executable to the /etc/shells file

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

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

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

紫竹語嫣☆ 2024-07-18 07:05:44

macOS v10.14 (Mojave) 上,我必须执行以下操作(使用 Z shell (zsh) 为例):

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

On macOS v10.14 (Mojave) I had to do the following (using Z shell (zsh) as an example):

brew install zsh
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)
掐死时间 2024-07-18 07:05:44

Homebrew 位于 M1 Mac 应使用 /opt/homebrew 而不是 /usr/local

您可以检查钓鱼位置钓鱼。 对我来说,Fish 位于 /opt/homebrew/bin/fish 中,这是我添加到 etc/shells 中的位置。

Homebrew on M1 Macs should use /opt/homebrew instead of /usr/local.

You can check the Fish location which fish. For me, Fish was in /opt/homebrew/bin/fish which was the location I have added to etc/shells.

仙女山的月亮 2024-07-18 07:05:44

如何在现代 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"

How to get the latest version of Bash on modern macOS (tested on macOS v10.14 (Mojave)).

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

Then you are ready to get Vim-style tab completion which is only available on Bash >= 4 (the current version in Homebrew is 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"
橘亓 2024-07-18 07:05:44

这对我来说在全新安装 Mac OS X v10.12 (Sierra) 时有效:

  1. 定义当前用户为 shell 的所有者

    sudo chown $(whoami) /etc/shells 
      
  2. 将 Fish 添加到文件 /etc/shells

    sudo echo /usr/local/bin/fish >>>   /etc/shell 
      
  3. Make Fish< /a> 你的默认 shell chsh

    chsh -s /usr/local/bin/fish 
      
  4. 重新定义 root 作为 shell 的所有者

    sudo chown root /etc/shells 
      

This work for me on fresh install of Mac OS X v10.12 (Sierra):

  1. Define the current user as the owner of shells

    sudo chown $(whoami) /etc/shells
    
  2. Add Fish to file /etc/shells

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

    chsh -s /usr/local/bin/fish
    
  4. Redefine root as the owner of shells

    sudo chown root /etc/shells
    
花海 2024-07-18 07:05:44

chsh 程序可以让您更改默认 shell。 它需要可执行文件的完整路径,因此如果您的 shell 是 Fish,那么它会要求您提供输入 whichfish 时给出的输出。

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

The chsh program will let you change your default shell. It will want the full path to the executable, so if your shell is Fish then it will want you to provide the output given when you type which fish.

You'll see a line starting with "Shell:". If you've never edited it, it most likely says "Shell: /bin/bash". Replace that /bin/bash path with the path to your desired shell.

淤浪 2024-07-18 07:05:44

要更改 Mac 上的默认 shell,请运行以下命令:

chsh -s <name-of-shell>

您可以选择的 shell 列表为:

  1. /bin/bash
  2. /bin/csh
  3. /bin/dash
  4. /bin/ksh
  5. /bin/sh
  6. /bin/tcsh
  7. /bin/zsh

因此,如果您想更改为 /bin/zsh shell,您的命令将如下所示:

chsh -s /bin/zsh

您可以通过运行以下命令查看系统上所有可用的 shell:

cat /etc/shells

To change your default shell on Mac, run the following:

chsh -s <name-of-shell>

The list of shells you can choose from are:

  1. /bin/bash
  2. /bin/csh
  3. /bin/dash
  4. /bin/ksh
  5. /bin/sh
  6. /bin/tcsh
  7. /bin/zsh

so if you want to change from to the /bin/zsh shell, your command will look like:

chsh -s /bin/zsh

You can see all the available shells on your system by running:

cat /etc/shells
逆夏时光 2024-07-18 07:05:44

终端中时,使用Command+,打开终端首选项。

在常规选项卡上,Shells open with:从默认登录 shell 更改为 Command
并使用 /bin/fish

When in the Terminal, open the terminal preferences using Command+,.

On the General Tab, Shells open with: change from Default login shell to Command:
and using /bin/fish

梦初启 2024-07-18 07:05:44

使用 dscl

heimdall:~ leeg$ dscl
Entering interactive mode... (type "help" for commands)
 > cd /Local/Default/Users/
/Local/Default/Users > read <<YOUR_USER>>
[...]
UserShell: /bin/bash
/Local/Default/Users >

只需更改该值(使用 write 命令dscl)。

Use dscl:

heimdall:~ leeg$ dscl
Entering interactive mode... (type "help" for commands)
 > cd /Local/Default/Users/
/Local/Default/Users > read <<YOUR_USER>>
[...]
UserShell: /bin/bash
/Local/Default/Users >

Just change that value (with the write command in dscl).

习惯成性 2024-07-18 07:05:44

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

which fish

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

In case you are having troubles with the other ways, the following worked on macOS v10.14 (Mojave), but it should generally work.

which fish

Add the output path to System PreferencesUsers & Groups → right click user, Advanced Options. Paste the result from which into filed "Login shell:".

睫毛上残留的泪 2024-07-18 07:05:44

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

exec /bin/bash

或您可能喜欢的任何 shell。

额外奖励:这不需要 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安装bash; 在这种情况下,您的 .zshrc 文件应该运行正确的 bash 版本。 目前是

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

Edit file .zshrc and change it to

exec /bin/bash

Or to whatever shell you might prefer.

Bonus: this doesn't require root access and will work on every version of OS X.

The only problem is that it doesn't read file .bash_profile this way; it is only read if Bash is run as an interactive login shell. You would have to include it from file .bashrc with something like this:

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

Also: The bash version that comes with osx is a bit dated, it is preferrable to install an up to date version of bash with brew install bash; in this case your .zshrc file should run the correct bash version. Currently that is

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文