You are not logged in.
Original title: 'Zsh PROMPT Ternary Expression Syntax Error for "%(!.true.false)"'
I'm trying to set up a custom PROMPT variable for zsh. I'm getting a syntax error when using the ternary expression syntax straight from the zsh documentation: http://zsh.sourceforge.net/Doc/Release/ … nsion.html
From the Arch wiki, the example works:
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg_no_bold[yellow]%}%1~ %{$reset_color%}%#"The zsh documentation says that the `%#` at the end is shorthand for `%(!.#.%%)`. If I expand `%#` to `%(!.#.%%)`, zsh throws a syntax error message:
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg_no_bold[yellow]%}%1~ %{$reset_color%}%(!.#.%%)"
zsh: event not found: .#I thought that the `#` might be a special character, so I tried this:
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg_no_bold[yellow]%}%1~ %{$reset_color%}%(!.root.home)"
zsh: event not found: .root.home)Then I tried removing everything but the ternary expression:
PROMPT="%(!.root.home)"
zsh: event not found: .root.home)And finally I tried using single characters:
PROMPT="%(!.r.h)"
zsh: event not found: .r.h)There has to be something small I'm missing because I'm copying and pasting straight from the zsh documentation. Does anyone know what it is?
Last edited by GreenRaccoon23 (2016-03-23 01:18:51)
Offline
From the very top of the page you linked to:
If the PROMPT_BANG option is set, a ‘!’ in the prompt is replaced by the current history event number. A literal ‘!’ may then be represented as ‘!!’.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Awesome! Thanks! Do you know how I'd be able to escape the "!" then?
-----EDIT-----
Got it! I just did:
PROMPT="%(\!.root.home)";Last edited by GreenRaccoon23 (2016-03-19 00:00:39)
Offline
I'm pretty sure unsetting PROMPT_BANG or the following would also work:
...A literal ‘!’ may then be represented as ‘!!’.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I'm pretty sure unsetting PROMPT_BANG or the following would also work:
...A literal ‘!’ may then be represented as ‘!!’.
Yeah, this works better. Otherwise, when I load up terminal (xfce4-terminal) from scratch, the expression does not appear to evaluate and strips off the rest of the line.
So, for clarity's sake, the fix is to add this in "~/.zshrc" before setting the $PROMPT variable.
unset PROMPT_BANG;Offline
Please remember to mark your thread as SOLVED. You might also go back and do the same for your previous threads that also have been solved.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Please remember to mark your thread as SOLVED. You might also go back and do the same for your previous threads that also have been solved.
Yeah when I couldn't figure out how to do that, I thought that you couldn't mark threads as solved on this forum. Apparently not. I'll try to figure that out again. It'd not very intuitive.
Last edited by GreenRaccoon23 (2016-03-23 01:16:15)
Offline
Trilby wrote:Please remember to mark your thread as SOLVED. You might also go back and do the same for your previous threads that also have been solved.
Yeah when I couldn't figure out how to do that, I thought that you couldn't mark threads as solved on this forum. Apparently not. I'll try to figure that out again. It'd not very intuitive.
Edit your first post in the thread. There is an option to edit the title when you edit the first post
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline