How to expand PS1?

后端 未结 7 1192
孤城傲影
孤城傲影 2020-11-27 17:57

I have a shell script that runs the same command in several directories (fgit). For each directory, I would like it to show the current prompt + the command which will be ru

7条回答
  •  青春惊慌失措
    2020-11-27 18:30

    Why don't you just process the $PS1 escape substitutions yourself? A series of substitutions such as these:

    p="${PS1//\\u/$USER}"; p="${p//\\h/$HOSTNAME}"
    

    By the way, zsh has the ability to interpret prompt escapes.

    print -P '%n@%m %d'
    

    or

    p=${(%%)PS1}
    

提交回复
热议问题