7

I want to add current time on git command prompt. with keeping the same actual parameters.

How to do it like the following image.

enter image description here

walidtlili
  • 840
  • 2
  • 13
  • 36
  • 1
    Possible duplicate of [short date in bash PS1 prompt](https://stackoverflow.com/questions/9200862/short-date-in-bash-ps1-prompt) – Joe Jun 23 '19 at 11:05
  • I've updated my answer to include a complete answer to your question. Please let me know if there is anything more you would like to know that related to this particular question. – Matthew Jun 23 '19 at 12:12
  • @joe i want to add date on prompt command – walidtlili Jun 23 '19 at 12:36

1 Answers1

10

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
Matthew
  • 1,905
  • 3
  • 19
  • 26
  • thx for repling, just i'm not finding the path of git on windows 10, if you can help me – walidtlili Jun 23 '19 at 12:38
  • The installation folder should have the same structure independent of operating system you're using. You're looking for the following file inside the directory **where you installed Git**: `\etc\profile.d` – Matthew Jun 23 '19 at 12:40
  • yes, just i forget and cant find where is my installed Git :D – walidtlili Jun 23 '19 at 12:44
  • 2
    One way would be to open your git bash console, then open your `windows task manager` and navigate to `Processes` tab. Right-click the `git-bash.exe` process from the list of image names and select `Open file location`. – Matthew Jun 23 '19 at 12:47
  • 1
    A perhaps simpler way would be to find it in the [list of installed programs](https://answers.microsoft.com/en-us/windows/forum/windows_10-start/how-do-i-find-my-installed-programs-windows-10/18432440-af63-43a9-b3bf-62ef6de2e8e8). – Matthew Jun 23 '19 at 12:49