LoginSignup
9
10

More than 5 years have passed since last update.

Terminalのプロンプト変数の変更

Last updated at Posted at 2012-04-20
Yoshinori-no-MacBook:~ sugiyama$ 

ターミナルには、常にホスト名、ディレクトリ名、ユーザ名が書かれてあって非常に目障りだったので、今日はここを短くする。

このときに表示されるこのような文字列をプロンプト変数と呼ぶらしい。

この変数の設定は、/etc/profile や.bashrcなどでPS1という変数を設定することで実現している.

\u はユーザ名 -->
\h はホスト名 -->
\w は作業ディレクトリ名

らしいので、おそらく・・・

PS1='\h:\w \u\$'

という風に設定されていると予測できる。

PS1='machine:\h dir:\w user:\u$'

と変更してみる。

machine:Yoshinori-no-MacBook dir:~ user:sugiyama$

こんな感じで長くなった。

実際にはこんなにいらないので、
ホスト名とユーザ名は表示なしで、

PS1='\w\$ '
~$

こんな感じでスッキリしました。

重要なコマンド
source ファイル名:再読み込み
(.bashrcをこれで読まないと変更が次回起動まで適用されない)

9
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
9
10