【问题标题】:escape % character in zsh在 zsh 中转义 % 字符
【发布时间】:2014-11-10 02:04:39
【问题描述】:
我正在尝试在提示符https://github.com/Goles/Battery 中添加电池插件。
PROMPT="╭─${user_host} ${current_dir} ${git_branch} `battery`
╰─%B$%b "
RPS1="${return_code}"
我需要转义百分号,这可以通过获取字符串输出然后用两个括号替换它来完成,但是我在编写脚本时失败了。我的提示看起来像顶行,但我希望它看起来像在第三行。有什么简单的解决方法吗?
【问题讨论】:
标签:
bash
zsh
zshrc
oh-my-zsh
【解决方案1】:
我从 github 执行 battery 命令时遇到问题,但我可能知道你的问题。我也用zsh。
在 zsh 中,您必须添加额外的 % 符号来转义 %。
您可以尝试将battery 命令更改为battery | sed 's/%/%%/',即您的提示符应如下所示:
PROMPT="╭─${user_host} ${current_dir} ${git_branch} `battery | sed 's/%/%%/'`
╰─%B$%b "