Reputation: 2993
tl;dr: How can I modify my host (%m
in prompt) such that it will be modified regardless of theme?
On my work computer, I cannot change my hostname. I have edited a (oh-my-)zsh theme to replace the host (%m
) when i'm on myridiculoushostname.evil.corp
with something shorter. I'd like to try out more (oh-my-)zsh themes (e.g. by setting my theme to random
), but I'd like to somehow modify just the host component of the prompt in all of them.
Upvotes: 0
Views: 1173
Reputation: 3139
Hacky Answer: do all of your magic in your root .zshrc
, and do it on the shell variable HOST
. For example, adding HOST="test"
to your .zshrc
will make %m
and %M
both read test
. The reason I called this hacky is HOST
is a general shell variable, and its possible other applications and scripts will check it's value.
'Right' Answer: Set your own prompt in your root .zshrc
, and handle the hostname magic the exact same way you handle it right now. This has the downside that the prompt for each theme isn't shown, but AFAIK there's no way to directly modify what %m evals to.
Answer so Scary I almost Didn't write it: At the end of your zshrc
, use awk to do a string replace on the PROMPT
variable. You can simply map %m
to a string of your choosing, effectively doing the prompt substitution for zsh. This will work no matter what theme you use, but it just seems obtuse.
e.g.: PROMPT=$(echo $PROMPT | sed 's/%m/test123/')
Upvotes: 1