bash - 通过配置PS1在提示符上显示当前时间
问题描述
我正在尝试配置PS1
显示当前时间,这是我当前的变量
me@host:~/Downloads$ env | grep -i 'ps1'
PS1=\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
计划的结果是
me@host; 09:00 AM: ~/Downloads$
\T 以 12 小时格式扩展为当前时间,
临时配置它
me@host:~/Downloads$ export PS1="\[\e]0;\u@\h;\T: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$"
不幸的是,提示没有改变。
我的使用有什么问题?
解决方案
- 如果双引号,则变量扩展将删除
debian_chroot
部分 - 字符串中嵌入了两个设置,但您只设置了一个:
- 第一个(您更改的)设置终端窗口的标题
- 第二个(您没有更改)设置命令提示符
尝试类似:
PS1='\[\e]0;\u@\h;\T: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\];\T:\[\033[01;34m\]\w\[\033[00m\]\$ '
推荐阅读
- javascript - 使用 NextJS 自定义路由名称
- c# - 使用动态 ID 定位元素的问题
- amazon-web-services - AWS 无服务器框架:嵌套堆栈或 Cloudformation 模板
- java - HQL:从 JSON 中选择
- r - 具有协变量的一阶删失自回归过程的可能性(参见 Jung Wook Park1、Marc G. Genton2 和 Sujit K. Ghosh3)
- sql - 在 SSIS 中具有固定块大小的顺序转换
- c++ - 让所有成员都活跃在 C++ 联合中是否安全?
- regex - 解析列数据框中的句点
- javascript - Vue.js - 如何将简单数组转换为动态 NxNxN 矩阵
- ubuntu - 无法在 ubuntu 服务器上安装 Nginx amplify