I want to add current time on git command prompt. with keeping the same actual parameters.
How to do it like the following image.
I want to add current time on git command prompt. with keeping the same actual parameters.
How to do it like the following image.
Navigate to your Git installation folder to where your profiles are located: Git\etc\profile.d
and open the file called git-prompt.sh
. Change the last block of code to include the time stamp like this:
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"' \A \D{%d/%m/%Y}' # time & date
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
Just to highlight, this is the line you are inserting just before bash inserts a new line:
PS1="$PS1"' \A \D{%d/%m/%Y}' # time & date
\A
will display the current time in 24-hour HH:MM
format and \D{format}
will display the date with a custom format. The format takes any arguments supported by strftime(3). The format we have used is broken down into these segments:
%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).
That should give you a following console output similar to this:
~/Desktop/Code/carhabti (master) 01:28 23/06/2019
Here is a list of escape sequences that are used to format time in 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