这个答案“如何分析 bash shell 脚本? ”似乎几乎完美地涵盖了我在这里尝试完成的工作。我目前有一些修改提示的 zsh 脚本,但是我认为 oh-my-zsh 的一些更新引发了一些我需要追查的问题。时不时的呆滞让人难以忍受。
为此,您将如何调整此示例答案中的提示部分以使用 zsh 与 bash?
目前我已经修改/etc/zshenv,使其具有示例中的初始建议代码:
PS4='+ $(date "+%s.%N")\011 '
exec 3>&2 2>/tmp/bashstart.$$.log
set -x
Run Code Online (Sandbox Code Playgroud)
我~/.zshrc的尾部附加了以下内容:
set +x
exec 2>&3 3>&-
Run Code Online (Sandbox Code Playgroud)
当然,这些对于 ZSH shell 定制是无效的。我的提示渲染代码使用 oh-my-zsh 自定义。我可以在我想的提示前添加适当的代码,或者我愿意接受其他建议。
你可能需要做
\n\nsetopt prompt_subst\nRun Code Online (Sandbox Code Playgroud)\n\n如果还没有的话。
\n\n另外,为了解释制表符的八进制转义,请使用$\'\':
PS4=$\'+ $(date "+%s.%N")\\011 \'\nRun Code Online (Sandbox Code Playgroud)\n\n您可能还会发现其中一些转义很有用:
\n\n %? The return status of the last command executed just before the prompt.\n\n %_ The status of the parser, i.e. the shell constructs (like `if\' and `for\') that have been started on the command\n line. If given an integer number that many strings will be printed; zero or negative or no integer means print as\n many as there are. This is most useful in prompts PS2 for continuation lines and PS4 for debugging with the\n XTRACE option; in the latter case it will also work non-interactively.\n\n %i The line number currently being executed in the script, sourced file, or shell function given by %N. This is most\n useful for debugging as part of $PS4.\n\n %I The line number currently being executed in the file %x. This is similar to %i, but the line number is always a\n line number in the file where the code was defined, even if the code is a shell function.\n\n %L The current value of $SHLVL.\n\n %N The name of the script, sourced file, or shell function that zsh is currently executing, whichever was started\n most recently. If there is none, this is equivalent to the parameter $0. An integer may follow the `%\' to spec\xe2\x80\x90\n ify a number of trailing path components to show; zero means the full path. A negative integer specifies leading\n components.\n\n %x The name of the file containing the source code currently being executed. This behaves as %N except that function\n and eval command names are not shown, instead the file where they were defined.\nRun Code Online (Sandbox Code Playgroud)\n