0
0

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 1 year has passed since last update.

プロンプトの色変更

Last updated at Posted at 2024-07-14

0.概要

プロンプトの色がデフォルトで白だったために,どこからがコマンドなのか非常にわかりづらい!そこで,プロンプトの色を変えることにします!という記事です.

本環境は,mac0Sで,シェルは,zshを使っています.

1.現状の把握

プロンプトの書式は次のコマンドで出力できます.

% echo $PS1
%n@%m %1~ %# 

この文字列を修正することで,プロンプトの文字の色を緑に,ディレクトリの色をマゼンタ色にします.

2.対処法

下記のコマンドを入力して下さい.

% PS1="%F{green}%n@%m%f %F{magenta}%1~%f %# ”

プロンプトの色が変更されたと思います.ただし,これでは,毎回変更する必要が出てくるので,/.zshrcファイルに書き込みましょう.

% echo "export PS1="%F{green}%n@%m%f %F{magenta}%1~%f %# "" >> ~/.zshrc
% source ~/.zshrc

これで再起動しても問題ありません.

3.仮想環境の色も変えよう

仮想環境に入ると,プロンプトの前に仮想環境名が入りますよね.この色が白色だと,やはり見づらいので,変更します.

% vim 仮想環境ディレクトリ名/bin/activate

上記のファイルを次のように変更します.

(変更前)
PS1="(仮想環境名) ${PS1:-}"
    export PS1

(変更後)
PS1=“%F{yellow}(仮想環境名)%f ${PS1:-}"
    export PS1

これで,仮想環境名を黄色にすることができました.
ただ,この方法では,それぞれの仮想環境に対して色の変更をする必要があるので,まとめて変更する必要があったら教えて下さい.

4.参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?