8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacOS Catalina でデフォルトのシェルが zsh になったので、fish る

Last updated at Posted at 2019-10-10

read it first

zsh を Mac のデフォルトシェルとして使う - Apple サポート
https://support.apple.com/ja-jp/HT208050

ターミナルを起動したらこんなメッセージが。

Last login: Thu Oct 10 14:40:11 on console

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

chsh -s /bin/zsh するとメッセージは消え、デフォルトシェルは zsh に。

折角なので、fish。

fish shell
https://fishshell.com/
https://fishshell.com/docs/current/tutorial.html

macOS 用パッケージマネージャー — Homebrew
https://brew.sh/index_ja

Homebrewでfish
brew install fish

正攻法で fish。

Switching to fish?

If you wish to use fish (or any other shell) as your default shell, you need to enter your new shell's executable /usr/local/bin/fish in two places:

  • add /usr/local/bin/fish to /etc/shells
  • change your default shell with chsh -s to /usr/local/bin/fish

You can use the following commands for this:

Add the fish shell /usr/local/bin/fish to /etc/shells with:

echo /usr/local/bin/fish | sudo tee -a /etc/shells

Change your default shell to fish with:

chsh -s /usr/local/bin/fish

(To change it back to another shell, just substitute /usr/local/bin/fish with /bin/bash, /bin/tcsh or /bin/zsh as appropriate in the steps above.)

実行例
esi@Mac-mini ~> cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
esi@Mac-mini ~> echo /usr/local/bin/fish | sudo tee -a /etc/shells
                
Password:
/usr/local/bin/fish
esi@Mac-mini ~> cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/fish
esi@Mac-mini ~> chsh -s /usr/local/bin/fish
Changing shell for esi.
Password for esi: 
esi@Mac-mini ~>

フィーッシュ!

スクリーンショット 2019-10-10 15.39.42.png

ターミナルの機能でfish。

  • ターミナルのメニューから、ターミナル>環境設定
  • 「プロファイル」で適当なプロファイルを選ぶ、もしくは新規作成
  • 「シェル」タブの「コマンドを実行」に /usr/local/bin/fish

※ 上記は少しふざけた手順です。真面目に設定する場合は zsh を Mac のデフォルトシェルとして使う - Apple サポート の「デフォルトを変更せずに別のシェルを使う方法」に従って下さい。

スクリーンショット 2019-10-10 15.53.58.png

※ 予期せぬトラブルを招かない為にも、/usr/local/bin に配置したシェルはアカウントのデフォルトとはせずにターミナル側で選択するのが無難かもしれません。

スクリーンショット 2019-10-10 16.25.37.png

※ /etc/shells に /usr/local/bin/fish を加えずに、「開くシェル:」で /usr/local/bin/fish を指定した場合、ターミナルの開始行に Last login:〜 以下のメッセージが表示されず、また、ウィンドウ左上の閉じるボタンで端末を閉じようとすると、以下のような警告メッセージが表示されます。この差異は「login」コマンドを経由するかしないかで生じるものと予想します。

スクリーンショット 2019-10-10 16.47.39.png

※ 確認しました

/etc/shells に登録されている場合
login -pf ユーザー名 /usr/local/bin/fish

スクリーンショット 2019-10-11 10.20.05.png

/etc/shells に登録されていない場合
login -pfq ユーザー名 /usr/local/bin/fish

スクリーンショット 2019-10-11 10.22.00.png

フィーッシュ!

スクリーンショット 2019-10-10 15.59.11.png

スクリーンショット 2019-10-10 16.29.31.png

スクリーンショット 2019-10-10 17.09.46.png

おまけ

fish 上の python3 で venv 仮想環境を有効化する場合

activate例
python3 -m venv ./py3env
source ./py3env/bin/activate.fish 
「activate.fish」ではなく「activate」と打つとコケる
> source ./py3env/bin/activate
./py3env/bin/activate (line 74): Missing end to balance this if statement
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
^
from sourcing file ./py3env/bin/activate
	called on standard input

source: Error while reading file './py3env/bin/activate'

※ fish スクリプトは少し csh 系に似ているかも。

参考とした文献

仮想環境 - python.jp
https://www.python.jp/install/macos/virtualenv.html

venv --- 仮想環境の作成 — Python 3.7.5rc1 ドキュメント
https://docs.python.org/ja/3/library/venv.html

パワーシェる。

PowerShellをデフォルトに
brew cask install powershell
echo /usr/local/bin/pwsh | sudo tee -a /etc/shells
chsh -s /usr/local/bin/pwsh

スクリーンショット 2019-10-11 10.04.28.png

スクリーンショット 2019-10-11 10.05.55.png

参考とした文献

ログインシェルにPowerShell Coreを使う - Qiita
https://qiita.com/yumiduka/items/75c93a30696a49a5564c
※ こちらの方の記事には環境変数まわりの調整も書かれていて丁寧です。

macOS への PowerShell Core のインストール - PowerShell | Microsoft Docs
https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-6

パワーシェルとは|「分かりそう」で「分からない」でも「分かった」気になれるIT用語辞典
https://wa3.i-3-i.info/word12683.html

8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?