让linux shell显示命令执行结果
vscode的shell可以用颜色来标记命令执行是否成功
如图,蓝色圆点表示成功,红色表示失败。但是默认的shell不可以。通过设置PS1可以实现这个功能。
在.bashrc文件中找到:
copyif [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
在之后添加一段:
copyold_color_prompt=$color_prompt
# BLACK='\[\e[0;30m\]'
RESET_COLOR='\[\033[00m\]'
GREEN='\[\033[0;32m\]'
RED='\[\033[0;31m\]'
PROMPT_COMMAND=smile_prompt
function smile_prompt
{
last_state=$?
if [ "$old_color_prompt" = yes ]; then
if [ "$last_state" -eq "0" ]; then
#smiley
PS1=${GREEN}'• '${RESET_COLOR}'${CONDA_PROMPT_MODIFIER}${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
#frowney
PS1=${RED}'• '${RESET_COLOR}'${CONDA_PROMPT_MODIFIER}${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
}
这样就可以了,同时兼顾了conda添加的前缀。
效果如下:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
2021-09-04 windows cmd 转义字符和双引号
2021-09-04 windows查看TCP连接