【发布时间】:2011-02-24 18:58:31
【问题描述】:
我想将我的bash提示设置为固定宽度,并弥补$之前的空格差异,所以无论长短,我的提示保持相同的宽度:
[name@host] ~/Directory/Dir...Another/LastDir $
[name@host] ~/Directory(branch) $
目前,在一个简短的目录路径中,我的提示看起来像这样:
[name@host] ~/Directory(branch) $
更深的目录路径如下所示:
[name@host] ~/Directory/Dir...Another/LastDir $
您可以看到我在中间截断了 PWD,因此我可以看到路径的起点和终点。我想补上$之前的差额。
这是我目前的提示:
# keep working directory to 30 chars, center tuncated
prompt_pwd() {
local pwd_symbol="..."
local pwd_length=30
newPWD="${PWD/#$HOME/~}"
[ ${#newPWD} -gt ${pwd_length} ] && newPWD=${newPWD:0:12}${pwd_symbol}${newPWD:${#newPWD}-15}
}
# set prompt
prompt_color() {
PROMPT_COMMAND='prompt_pwd;history -a;title_git'
PS1="${WHITEONMAGENTA}[\u@\h]${MAGENTA} \w\$(parse_git_branch) ${MAGENTABOLD}\$${PS_CLEAR} "
PS1=${PS1//\\w/\$\{newPWD\}}
PS2="${WHITEONTEAL}>${PS_CLEAR} "
}
在我的搜索中,我找到了A Prompt the Width of Your Term,它确实做了一些填充,但无法让它适用于这个特定的提示。
【问题讨论】:
标签: macos bash .bash-profile