LoginSignup
4
4

More than 3 years have passed since last update.

fishで任意のPATHを設定・削除する方法

Posted at

設定する時

他のshellの場合

bash,zsh,tcshのような旧来のshellの場合, インタラクティブshellが開始する際に必ず実行されるshell scriptである.*shrcに追記することでPATHが追加できる.

~/.zshrc
export PATH="$PATH:/Users/yas-nyan/.nodebrew/current/bin"

fishの場合

fishでは以下の様に各セッション共通のPATHをCLIから設定する.
参考:fish shellのPATH設定

~/
set -U fish_user_paths  /Users/yas-nyan/.nodebrew/current/bin $fish_user_paths

結果的に以下のようなファイルにfishが生成した変数が追加される.以下は一例.

~/.config/fish/fishd.*****
SET fish_user_paths:/usr/local/opt/openssl/bin\x1e/Users/yas\x2dnyan/\x2enodebrew/current/bin\x1e/usr/local/Cellar/mtr/0\x2e92/sbin

削除する時

他のshellの場合

他のshellであれば~/.*shrcに宣言的に記述されるので,不要になった場合は当該行を消せば良い.

~/.zshrc
- export PATH="$PATH:/Users/yas-nyan/.nodebrew/current/bin"

fishの場合

fishでは設定する時と同じ様に,以下の様にCLIから削除する.

まず, 現在設定されているPATHを表示する.

~/
echo $fish_user_paths
/Users/yas-nyan/.nodebrew/current/bin /usr/local/Cellar/mtr/0.92/sbin /usr/local/opt/openssl/bin

例えば/usr/local/Cellar/mtr/0.92/sbinを削除するとする.
当該PATHは$fish_user_pathsの2番目なので,以下の様なコマンドを実行する.
この時, indexは1から始まるので注意する.

~/
set -e $fish_user_paths[2]

おまけ

$fish_user_pathsが沢山ある場合何番目に登録されているかを確認するのは大変.

pathが何番目か表示するワンライナーは以下の通り.

~/
echo $fish_user_paths | tr  ' ' '\n' | nl

以下のようにわかりやすく出力される.適当にgrepして使って下さい.

~/
 1  /Users/yas-nyan/.nodebrew/current/bin
 2  /usr/local/Cellar/mtr/0.93_1/sbin
 3  /usr/local/opt/openssl/bin
4
4
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
4
4