Anaconda Navigatorでターミナルを開くときにfish shellで開けるようにする

Anaconda Navigatorを使ってみたけどfish shellに対応していないらしく無理やり対応した。 きちんと読み込めたけど、また何か問題がでれば追記する。

対処方法

対処法は~/opt/anaconda3/bin/activateを以下のように書き換える。 diff形式なので-の部分を消して、+の部分を追加する。

 #!/bin/sh
-_CONDA_ROOT="/Users/pogin/opt/anaconda3"
+set _CONDA_ROOT "/Users/pogin/opt/anaconda3"
 # Copyright (C) 2012 Anaconda, Inc
 # SPDX-License-Identifier: BSD-3-Clause
-\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
-conda activate "$@"
+\. "$_CONDA_ROOT/etc/fish/conf.d/conda.fish";or $status
+conda activate $argv
Last login: Mon Jun 15 07:43:16 on ttys003
. /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/opt/anaconda3/envs/PyTorch_Practice; 
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
⋊> ~ . /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/optanaconda3/envs/PyTorch_Practice; 
⋊> ~ type pip                                        (PyTorch_Practive)
pip is /Users/pogin/opt/anaconda3/envs/PyTorch_Practive/bin/pip
⋊> ~                                                 (PyTorch_Practive)

試行錯誤のメモ

~/opt/anaconda3/bin/activate (line 2): Unsupported use of '='. In fish, please use 'set _CONDA_ROOT "/Users/pogin/opt/anaconda3"'.

bashのShell Scriptをそのまま読み込むときにときにみたことありそうなやつ。

Last login: Mon Jun 15 07:44:21 on ttys004
. /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/opt/anaconda3/envs/PyTorch_Practive; 
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
⋊> ~ . /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/optanaconda3/envs/PyTorch_Practive; 
~/opt/anaconda3/bin/activate (line 2): Unsupported use of '='. In fish, please use 'set _CONDA_ROOT "/Users/pogin/opt/anaconda3"'.
from sourcing file ~/opt/anaconda3/bin/activate
    called on line 185 of file /usr/local/Cellar/fish/3.1.0_1/share/fish/config.fish
in function '.' with arguments '/Users/pogin/opt/anaconda3/bin/activate'
source: Error while reading file '/Users/pogin/opt/anaconda3/bin/activate'

中身を見てみる。

emacsclient /Users/pogin/opt/anaconda3/bin/activate
#!/bin/sh
_CONDA_ROOT="/Users/pogin/opt/anaconda3"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
conda activate "$@"

シェバンが#!/bin/shなのでfishで読み込んでるのエラーになる。なので_CONDA_ROOTを書き換える。

 #!/bin/sh
-_CONDA_ROOT="/Users/pogin/opt/anaconda3"
+set _CONDA_ROOT "/Users/pogin/opt/anaconda3"

~/opt/anaconda3/bin/activate (line 6): 'return' outside of function definition

bash用の記法なのでreturnがダメらしい。 なのでreturnと$?も書き換えとく。 ついでにconda.fishを読み込んでないのでパスを書き換えないといけない。

. /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/opt/anaconda3/envs/PyTorch_Practive; 
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
⋊> ~ . /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/optanaconda3/envs/PyTorch_Practive; 
~/opt/anaconda3/bin/activate (line 6): 'return' outside of function definition
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
                                            ^
from sourcing file ~/opt/anaconda3/bin/activate
    called on line 185 of file /usr/local/Cellar/fish/3.1.0_1/share/fish/config.fish
in function '.' with arguments '/Users/pogin/opt/anaconda3/bin/activate'
source: Error while reading file '/Users/pogin/opt/anaconda3/bin/activate'

修正するとこうなった。

-\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
+\. "$_CONDA_ROOT/etc/fish/conf.d/conda.fish";or $status

~/opt/anaconda3/bin/activate (line 8): $@ is not supported. In fish, please use $argv.

fishは$@をサポートしてないので代わりに$argvを使ってくれとのことなので書き換えないといけない。

. /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/opt/anaconda3/envs/PyTorch_Practive; 
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
⋊> ~ . /Users/pogin/opt/anaconda3/bin/activate && conda activate /Users/pogin/optanaconda3/envs/PyTorch_Practive; 
~/opt/anaconda3/bin/activate (line 8): $@ is not supported. In fish, please use $argv.
conda activate "$@"
                 ^
from sourcing file ~/opt/anaconda3/bin/activate
    called on line 185 of file /usr/local/Cellar/fish/3.1.0_1/share/fish/config.fish
in function '.' with arguments '/Users/pogin/opt/anaconda3/bin/activate'
source: Error while reading file '/Users/pogin/opt/anaconda3/bin/activate'
-conda activate "$@"
+conda activate $argv

ここまでやってようやくエラーが出なくなった。