如何在git命令提示符下添加时间

时间:2019-06-23 11:03:33

标签: git command-prompt

我想在git命令提示符下添加当前时间。并保持相同的实际参数。

  

操作方法如下图。

enter image description here

1 个答案:

答案 0 :(得分:2)

导航至配置文件所在的Git安装文件夹:Git\etc\profile.d,然后打开名为git-prompt.sh的文件。更改最后一个代码块以包括时​​间戳,如下所示:

PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"' \A \D{%d/%m/%Y}'   # time & date
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

突出显示,这是您在bash插入新行之前要插入的行:

PS1="$PS1"' \A \D{%d/%m/%Y}'   # time & date

\A将以24小时HH:MM格式显示当前时间,而\D{format}将以自定义格式显示日期。该格式采用strftime(3)支持的所有参数。我们使用的格式分为以下几部分:

%m - The month as a decimal number (range 01 to 12). 
%d - The day of the month as a decimal number (range 01 to 31). 
%y - The year as a decimal number without a century (range 00 to 99).

这应该为您提供以下类似于以下内容的控制台输出:

~/Desktop/Code/carhabti (master) 01:28 23/06/2019

这是list的转义序列,用于在bash中格式化时间:

\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format