ZSH プロンプト: 現在のディレクトリ以外のパス

ZSH プロンプト: 現在のディレクトリ以外のパス

zshはプロンプトをパス全体に設定できますかを除外する現在のディレクトリですか? つまり、~/a/b/c/単に~/a/b/?

~/a/b/c左と右のプロンプトで次の結果を取得しようとしています:

c/: | ~/a/b/

現在の複製とは対照的にc:

c/: | ~/a/b/c/

cディレクトリ名が長い場合、重複によりスペースが無駄になります。

の中にマニュアル私が望んでいたもの以外はすべて見つかりました:

  • %-1~- パスの最初の要素
  • %1~- パスの最後の要素

最後以外すべてではなく

どうすればそれができるのでしょうか?

答え1

# Before printing each prompt string, apply substitutions to it.
setopt promptsubst

# $PWD is always equal to the present working dir.
# :h chops off the last item of the path.
# (D) substitutes the start of the path with a named dir, such as ~, if possible.
# Note that this string is in 'single quotes'!
RPS1='${(D)PWD:h}'

やったー!

ドキュメンテーション:

関連情報