Here is my new oh-my-zsh zsh-theme, updated with an escape character before each code block within $()'s which allows it to update every time the prompt is displayed (works with setopt prompt_subst
:
PROMPT="%F{yellow}%n%F{white}@%F{green}%M %F{cyan}%j %F{white}\$(curl -s https://api.myip.com | jq .ip -r) %F{green}%2c%F{cyan} [%f "
RPROMPT="\$(git_prompt_info) %F{cyan}] %F{red}\$(top -l 1 | grep 'Load Avg' | awk '{print $3, $4, $5}' | tr -d , | awk '{print $2}')[\$(sysctl hw.ncpu | grep -o -E '[1-9]+')] @ \$(top -l 1 | grep 'CPU usage:' | awk '{print $3, $5, $7}' | tr -d , | awk '{print $3,"%%"}') idle %F{green}%W %* %F{yellow}%D{%p}%f"
ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%f"
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{red}*%f"
ZSH_THEME_GIT_PROMPT_CLEAN=""
It will dynamically change the date and time, the IP address, and the git_prompt_info, every time I press return, but the shell scripting like \$(top -l 1 | grep 'Load Avg' | awk '{print $3, $4, $5}' | tr -d , | awk '{print $2}')
does not update every time I press "return", it gives me an error instead:
awk: syntax error at source line 1
context is
{print >>> , <<<
awk: illegal statement at source line 1
awk: illegal statement at source line 1
What's going on here?
RPROMPT
from a double-quoted-string. This means that$1
inside will be replaced by the shell. You would have to escape the $, i.e. write\$1
.