如何去除 *WINDOWS* git bash 提示的日期时间格式的前导 zeros/spaces?
How to strip leading zeros/spaces in datetime format for *WINDOWS* git bash prompt?
此提示适用于我在 Ubuntu 中的终端:
PS1="[\D{%-m/%-d %-l:%M:%S %P}] \u@\h:\w$ "
但是在我的 git bash 终端 Windows VSCode 中,该提示的日期时间部分中断了——它显示为空字符串。它不喜欢格式说明符中的“-”。还有另一种方法吗?例如,像 5 月 9 日这样的日期应该这样显示:[5/9 1:23:07 pm]
,而不是像这样 [05/09 01:23:07 pm]
或这样 [ 5/09 1:23:07 pm]
。由于提示出现在上方我的命令,所以用填充排列日期时间字段对我来说并不重要。
注意:%#m
也不起作用,尽管如此 strftime documentation from Microsoft。
如果相关,这里是我的整个提示的完整(损坏)脚本:
PS1='\[3]0;$TITLEPREFIX:$PWD[=15=]7\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[3[32m\]' # change to green
PS1="$PS1"'[\D{%-m/%-d %-l:%M:%S %P}] ' # date & time
PS1="$PS1"'\[3[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
我认为也许在 PS1 提示符下使用日期命令可以帮助您获得所需的结果。请找到以下 shell 替换,
PS1="$(date +'%-m/%-d %-l:%M:%S %P') $"
上面的这个确实适用于我的 git bash 提示。我希望这对您有所帮助。
此提示适用于我在 Ubuntu 中的终端:
PS1="[\D{%-m/%-d %-l:%M:%S %P}] \u@\h:\w$ "
但是在我的 git bash 终端 Windows VSCode 中,该提示的日期时间部分中断了——它显示为空字符串。它不喜欢格式说明符中的“-”。还有另一种方法吗?例如,像 5 月 9 日这样的日期应该这样显示:[5/9 1:23:07 pm]
,而不是像这样 [05/09 01:23:07 pm]
或这样 [ 5/09 1:23:07 pm]
。由于提示出现在上方我的命令,所以用填充排列日期时间字段对我来说并不重要。
注意:%#m
也不起作用,尽管如此 strftime documentation from Microsoft。
如果相关,这里是我的整个提示的完整(损坏)脚本:
PS1='\[3]0;$TITLEPREFIX:$PWD[=15=]7\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[3[32m\]' # change to green
PS1="$PS1"'[\D{%-m/%-d %-l:%M:%S %P}] ' # date & time
PS1="$PS1"'\[3[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
我认为也许在 PS1 提示符下使用日期命令可以帮助您获得所需的结果。请找到以下 shell 替换,
PS1="$(date +'%-m/%-d %-l:%M:%S %P') $"
上面的这个确实适用于我的 git bash 提示。我希望这对您有所帮助。