这是我的 .bashrc 或至少包含提示的部分 -
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -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
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\A\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\d:\A\$ '
fi
unset color_prompt force_color_prompt
现在可以看到我的提示是 -
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\d\A\$ '
现在我最关心的是日期和时间之间是否可以有空格
\d\A
因为提示看起来像这样 -
shirish@think-debian:~Tue Oct 2001:03$
更大的问题是,除非我知道语法,否则提示符是不可读的。有办法解决这个问题吗?
答案1
您可以逐步积累价值,并一路发表评论
PS1='\u@\h:' # User@Host:
PS1+='\w' # Working directory
PS1+='\d' # date
PS1+=' '
PS1+='\A' # Time
PS1+='\$ ' # Marker
答案2
现在我最关心的是日期和时间之间是否可以有空格
是的。在日期和时间之间添加一个空格:
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\d \A\$ '
更大的问题是,除非我知道语法,否则提示符是不可读的。有办法解决这个问题吗?
您可以根据需要向提示中添加任意文本:
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w date:\d time:\A\$ '
答案3
PS1='\u@\h:\w \d \A\$ '
可读性走向极端:
declare -A prompt=(
[user]='\u'
[host]='\h'
[dir]='\w'
[date]='\d'
[time]='\A'
[prompt]='\$ '
)
PS1="${prompt[user]}@${prompt[host]}:${prompt[dir]} ${prompt[date]} ${prompt[time]} ${prompt[prompt]}"