6

この回答「bashシェルスクリプトのプロファイリング方法は?」は、私がここで達成しようとしていることをほぼ完全にカバーしているようです。現在、プロンプトを変更するzshスクリプトがいくつかありますが、oh-my-zshを更新すると、追跡する必要のある問題が発生したと思います。時々の鈍さは耐え難いです。

この目的のために、この例の回答のプロンプトセクションをzshとbashで動作するようにどのように適合させますか?

現在/etc/zshenv、例から最初に提案されたコードが含まれるように変更しました。

PS4='+ $(date "+%s.%N")\011 '
exec 3>&2 2>/tmp/bashstart.$$.log
set -x

そして、私~/.zshrcの尻尾には次のものが追加されています。

set +x
exec 2>&3 3>&-

もちろん、これらはZSHシェルのカスタマイズには無効です。私のプロンプトレンダリングコードは、oh-my-zshのカスタマイズを利用しています。想定するプロンプトの前に適切なコードを追加するか、他の提案を受け入れることができます。

4

2 に答える 2

2

あなたがする必要があるかもしれません

setopt prompt_subst

まだではない場合。

また、タブの 8 進エスケープを解釈するには、次を使用します$''

PS4=$'+ $(date "+%s.%N")\011 '

これらのエスケープのいくつかが役立つ場合もあります。

   %?     The return status of the last command executed just before the prompt.

   %_     The  status  of  the parser, i.e. the shell constructs (like `if' and `for') that have been started on the command
          line. If given an integer number that many strings will be printed; zero or negative or no integer means print  as
          many  as  there  are.   This  is  most useful in prompts PS2 for continuation lines and PS4 for debugging with the
          XTRACE option; in the latter case it will also work non-interactively.

   %i     The line number currently being executed in the script, sourced file, or shell function given by %N.  This is most
          useful for debugging as part of $PS4.

   %I     The line number currently being executed in the file %x.  This is similar to %i, but the line number is  always  a
          line number in the file where the code was defined, even if the code is a shell function.

   %L     The current value of $SHLVL.

   %N     The  name  of  the  script, sourced file, or shell function that zsh is currently executing, whichever was started
          most recently.  If there is none, this is equivalent to the parameter $0.  An integer may follow the `%' to  spec‐
          ify  a number of trailing path components to show; zero means the full path.  A negative integer specifies leading
          components.

   %x     The name of the file containing the source code currently being executed.  This behaves as %N except that function
          and eval command names are not shown, instead the file where they were defined.
于 2012-01-18T17:18:13.150 に答える