9

このoh-my-zshテーマをカスタマイズしようとしています。

私はその中にこのコードを見つけました。これは明らかにdir名を出力します(間違っている場合は訂正してください)。

# Dir: current working directory
prompt_dir() {
  prompt_segment blue black '%~'
}

そしてprompt_segmentは次のように定義されます

# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
  local bg fg
  [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
  [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
  if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
    echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
  else
    echo -n "%{$bg%}%{$fg%} "
  fi
  CURRENT_BG=$1
  [[ -n $3 ]] && echo -n $3
}

この出力は、必ずしもディレクトリパスだけではありません。ENV変数にも存在するパスにいる場合、パスはその変数に置き換えられます。

私がいる場合

/Users/abc/.oh-my-zsh/custom

そして$ZSH_CUSTOMは

/Users/abc/.oh-my-zsh/custom

$ZSH_CUSTOMコマンドプロンプトが表示されます。

だから私の質問は、1)何%~から送信されているのかprompt_dir、2)現在の作業ディレクトリを取得するこのコーディングの部分はどこにあるのか、3)常に実際のパスを出力するようにするにはどうすればよいですか。

4

1 に答える 1

16

EXPANSION OF PROMPT SEQUENCESのセクションを参照してくださいman zshmisc

   %d
   /      Current  working  directory.   If an integer follows the `%', it
          specifies a number of trailing components of the current working
          directory  to show; zero means the whole path.  A negative inte‐
          ger specifies leading components, i.e. %-1d specifies the  first
          component.

   %~     As  %d  and %/, but if the current working directory has a named
          directory as its prefix, that part is replaced by a `~' followed
          by  the  name  of  the directory.  If it starts with $HOME, that
          part is replaced by a `~'.
于 2012-12-01T15:07:38.383 に答える