Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Currently my bash prompt looks like this

$ echo $PS1
# \[\e[34m\][\t]\[\e[0m\] \[\e]0;\w\a\]\[\e[34m\]\u@\h: \[\e[34m\]\w\[\e[0m\]\n$
$

The problem is that \t will only display the time when the prompt was rendered (which would be very close to the time of completion of the last command).

For me, it would be more useful to display the time at which the current command process was started. Is there a way to do this?

share|improve this question
    
I wonder what difference it will make to your prompt? A few milliseconds cannot cause problems, can they? –  phunehehe Oct 24 '10 at 8:20
1  
There are some commands which will take a little bit longer ;-) –  echox Oct 24 '10 at 9:45
add comment

2 Answers

up vote 5 down vote accepted

If I understand you correctly, you want to change the prompt when you start the current command. I don't think bash has a prompt-changing feature, but you can perhaps redraw over the prompt, if you can locate it (not so easy for multi-line commands).

In zsh, you would use the precmd function. Bash doesn't have a similar feature, but it can be hacked up.

share|improve this answer
add comment

No, because there could be any length of time between the prompt and you entering your command, and then pressing the ENTER key.

You could set up an alias for a non command (say doit) that displayed the time and then execute the command it was passed. It would require you remembering to use it every time, and it would only work on systems (and accounts) that you'd configured it on.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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