![](/img/trans.png)
[英]How to override fish_prompt, keeping the styles from the applied theme?
[英]if statement in fish_prompt
我正在尝试自定义我的鱼提示,但我似乎无法在其中添加 if 语句。
我想要什么: user@host ~/.config [127]>
我尝试了什么:
function fish_prompt
echo -n $USER
echo -n "@"
echo -n $hostname
echo -n " "
echo -n (prompt_pwd)
echo -n (__fish_git_prompt)
if [ $status -ne 0 ]
echo -n " [$status] "
end
echo -n "> "
end
我希望 $status 仅在出现错误时显示。 到目前为止,除了if
语句,一切正常。 ( if
直接在控制台中我尝试了同样的方法并且它有效,问题仅出现在fish_prompt中)。
谢谢
echo
还返回一个状态,因此 $status 被更新。
因此,如果您对命令行的 $status 感兴趣,则需要先保存它,然后再执行其他任何操作。
做这个:
function fish_prompt
# $status here is what the commandline returned,
# save it so we can use it later
set -l laststatus $status
echo -n $USER
echo -n "@"
echo -n $hostname
echo -n " "
echo -n (prompt_pwd)
echo -n (__fish_git_prompt)
if [ $laststatus -ne 0 ]
echo -n " [$laststatus] "
end
echo -n "> "
end
这也是fish的示例提示所做的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.