escape % character in zsh

2.4k views Asked by At

I am trying to add a battery blugin to my prompt https://github.com/Goles/Battery.

PROMPT="╭─${user_host} ${current_dir} ${git_branch} `battery`
╰─%B$%b "
RPS1="${return_code}"

I need to escape the percent sign, which can be done by getting the string output and then replacing it with two parenthesis, but I have failed at scripting that. My prompt looks like the top line but I want it to appear like it is in the third line. Any easy fixes to this?

1

There are 1 answers

0
DragonHu On BEST ANSWER

I have problem executing the battery command from the github, but I may know you problem. I use zsh too. In zsh you have to add additional % sign to escape the %. You can try to change the battery command to battery | sed 's/%/%%/', i.e, your prompt should look like this:

PROMPT="╭─${user_host} ${current_dir} ${git_branch} `battery | sed 's/%/%%/'`
╰─%B$%b "