所以,我已经启动并运行了我的Zsh,并且我正在创建我自己的新的zsh主题。在它中,我希望从https://api.myip.com获取外部IP地址-我使用curl & grep来获取它。当我在命令提示符下输入它时,它工作得很好,但是当它嵌入到我的zsh主题文件中时,它会给我一个错误:
zsh: no matches found: ((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5]).){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])
(23) Failed writing body
Jacobs-MacBook-Pro-2.local jacobjackson ttys002 0 [ ] 10/29/20 18:32:46 PM下面是我的zsh主题:
PROMPT='%F{white}%M %n %y %j $(curl -s https://api.myip.com | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])') %F{green}%2c%F{blue} [%f '
RPROMPT='$(git_prompt_info) %F{blue}] %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=""下面是获取IP地址的命令序列:
curl -s https://api.myip.com | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])'发布于 2020-11-30 21:13:43
试试这个:
# Function name that's compatible with
# http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Prompt-Themes
# in case you ever want to build a full prompt theme.
# `-s` to prevent `curl` from outputting a progress bar.
# Use a service that simply outputs our IP, so we don't have to parse anything.
prompt_jacobjackson_precmd() {
psvar[1]=$(curl -s ifconfig.co)
}
# `precmd` hooks get executed just before each new prompt.
autoload -Uz add-zsh-hook
add-zsh-hook precmd prompt_jacobjackson_precmd
# `%1v` inserts the 1st element of the `psvar` array. See
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Conditional-Substrings-in-Prompts
PS1='%1v > 'https://stackoverflow.com/questions/64601466
复制相似问题