メニュー 閉じる

cygwin上のzshのプロンプトがおかしいのでカスタマイズしてみる

zshを入れてみた

cygwinの標準シェルはbashですが、zshを使おうと思ってzshを入れたは良いものの、bashのプロンプトをそのまま流用されてしまって変なことに。

見事にエスケープ文字がそのまま出力されています…
せっかくなのでzshのプロンプトをカスタマイズすることにします。

カスタマイズと言っても…

細かい設定は一旦置いといて、テーマで設定することにしてみます。

$ man zshall

と入力してマニュアルを表示してみると、

       promptinit
              a prompt theme system for changing prompts easily, see the section `Prompt Themes'

どうやらpromptinitと言うものがあるらしい。
see the section Prompt Themesということなので、下の方の「PROMPT THEMES」を見ます。

PROMPT THEMES
   Installation
       You should make sure all the functions from the Functions/Prompts directory of the source distribution are available; they all begin with the  string  `prompt_'  except
       for  the special function`promptinit'.  You also need the `colors' function from Functions/Misc.  All of these functions may already have been installed on your system;
       if not, you will need to find them and copy them.  The directory should appear as one of the elements of the fpath array (this should already be the case if  they  were
       installed),  and  at  least  the function promptinit should be autoloaded; it will autoload the rest.  Finally, to initialize the use of the system you need to call the
       promptinit function.  The following code in your .zshrc will arrange for this; assume the functions are stored in the directory ~/myfns:

              fpath=(~/myfns $fpath)
              autoload -U promptinit
              promptinit

   Theme Selection
       Use the prompt command to select your preferred theme.  This command may be added to your .zshrc following the call to promptinit in order to start  zsh  with  a  theme
       already selected.

       prompt [ -c | -l ]
       prompt [ -p | -h ] [ theme ... ]
       prompt [ -s ] theme [ arg ... ]
              Set  or  examine the prompt theme.  With no options and a theme argument, the theme with that name is set as the current theme.  The available themes are deter‐
              mined at run time; use the -l option to see a list.  The special theme `random' selects at random one of the available themes and sets your prompt to that.

              In some cases the theme may be modified by one or more arguments, which should be given after the theme name.  See the help for each theme  for  descriptions  of
              these arguments.

              Options are:

              -c     Show the currently selected theme and its parameters, if any.
              -l     List all available prompt themes.
              -p     Preview the theme named by theme, or all themes if no theme is given.
              -h     Show help for the theme named by theme, or for the prompt function if no theme is given.
              -s     Set theme as the current theme and save state.

ふむふむ。

まずインストールが必要なようなので、promptinitを読み込ませましょう。
一応.zshrcにも追記しておきます。

$ autoload -U promptinit
$ promptinit

その後は取りあえず、-pでプレビュー表示して-sで保存すれば使えそうですね。
では早速プレビューを表示してみます。

カラフルなテーマがたくさん出てきました。
この中からよさげなものを選択してみることにします。

$ prompt -s bigfade red white grey white
Set and save not yet implemented.  Please ensure your ~/.zshrc
contains something similar to the following:

  autoload -Uz promptinit
  promptinit
  prompt bigfade red white grey white

これでプロンプトのデザインが変わりました!
言われたとおり、.zshrcも編集しておきましょう。

Posted in Linux

関連投稿

1件のコメント

  1. ピンバック:cygwinのログインシェルをbashにする | ITログ

コメントを残す

Amazon プライム対象