12

zsh の入力テキスト (コマンドごとに入力するテキスト) の色を変更したい。例: in標準出力から目立つように黄色にしuser@host> ls ~/たいと思います。ls ~/

私はbashでこれを達成できることを知っています

export PS1=" $BIGreen \u@\h \w \$ $IYellow" 

プロンプトの最後で、色は黄色に設定され、入力テキストは黄色です (適切な色変数が定義されています)。その後

trap 'echo -ne "\e[0m"' DEBUG

コマンドの出力が表示されるときに、色を通常の色にリセットします。

zshでこれを達成するにはどうすればよいですか? 現在、私は

PROMPT=$'{$fg[green]%}%n@%{$fg[green]%}%m %# %{$fg[yellow]%}'

.zshrc (最後に色を黄色に設定) では機能しますが、機能しません。(コマンドの後に色を白に戻す方法もわかりません)。

4

1 に答える 1

11

Try this:

PROMPT="%F{green}%n@%m %# %F{yellow}"
preexec () { echo -ne "\e[0m" }

I tried using trap, but it looks like DEBUG doesn't happen until after the command runs/before the next prompt, so the command ends up executing in yellow. The preexec() function gets called before the command executes, so you can restore the default color there.

于 2012-11-29T22:08:22.580 に答える