0
1

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.

【fishシェルのテンプレ】$PATHにパスを追加する(「Googleの中の人」ver)

Posted at

テンプレ

解説はインラインのコメントを参照してください。

# The begin/end block limits the scope of all variables except $PATH
# begin/endは(-xでexportしている)$PATH以外のすべての変数スコープを限定するよ
begin

  # 例として/opt/binを追加します
  set new_path "/opt/bin"

  # -gx for global (not limited to this begin/end block) and exportable (part of
  # the environment for child processes)
  # -gxはグローバル化(begin/endブロック以外の場所からも使えるようにする)とエクスポート(個プロセスでも使える環境変数にする)の為に使っているよ
  if not contains "$new_path" $PATH
    set -gx PATH "$new_path" $PATH
  end

end

経緯

最近、google-cloud-sdkを対話スクリプトでインストールした際、次のような対話項目がありました。

Enter a path to an rc file to update, or leave blank to use 
[/home/dev-user/.config/fish/config.fish]:

この手のパス追加はB系シェルを前提としたものが多いので、fishシェルを使っている身としては嬉しい限りです。上記config.fishに追加されていた設定スクリプトを開いたところ、私のような輩を想定していたのか各行に初心者向けのコメントがついていたので、感動して記事にしました。(コメントの英語部分はオリジナルそのままです。)

ありがとうございます、Googleの中の人

0
1
2

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?