11

I run git's bash on Windows7 to manage source control for projects.

Can I edit C:\Program Files (x86)\Git\etc\git-prompt.sh to enable me to timestamp when I ran commands?

e.g. instead of

user.name@machine /c/somedirectory
$ git pull origin develop
remote: Counting objects: 1, done.

Displaying

user.name@machine /c/somedirectory
$ git pull origin develop
21/04/2016 20:15:33
remote: Counting objects: 1, done.

So I can know whether something was run before/after a particular time.

12

This is solution to your problem, only difference from what you wrote, is that timestamp is displayed after the command output, and not before.

Under the Windows Program Files folder, open Git\etc\profile or Git\etc\profile.d\git-prompt.sh, search for lines which look like:

PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change color
PS1="$PS1"'\u@\h '             # user@host<space>
PS1="$PS1"'\[\033[33m\]'       # change color
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    PS1="$PS1"'$(__git_ps1)'   # bash function
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

And add line

PS1="$PS1"' \t'                # time

before second-to-last line. That will give you prompt like:

user.name@machine /c/somedirectory 18:34:35
$ git pull origin develop
remote: Counting objects: 1, done.

user.name@machine /c/somedirectory 18:42:12
$

Here is list of other useful options you can add: http://makandracards.com/makandra/1090-customize-your-bash-prompt

  • I guess if you press enter to create a blank prompt before you execute the script, that might give you a start time. The end time would be the next prompt that appears after process executes and ends. – Sun Jun 1 '16 at 21:12
  • 2
    I've used a slight variation so that the time stamp remains on a separate line instead of cluttering the bash command line. PS1='[\t]'"$PS1" # time – Shiyaz Sep 13 '17 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.