Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to add the current time upon execution of a bash command. I would like it to be in the right hand site so not to be intrusive. The output I am looking for is:

batman@Batcave:~/grails$ ls -l
total 84
drwxr-xr-x 2 batman batman  4096 2011-02-16 09:54 bin
drwxr-xr-x 2 batman batman  4096 2011-02-16 08:24 scripts
drwxr-xr-x 9 batman batman  4096 2011-02-16 08:24 src
batman@Batcave:~/grails$                                                       **10:46:06**

ideas on how to accomplish this??

share|improve this question
    
What's the aim here? Just to show the current time or to show the time that something completed? –  Oli Apr 4 '12 at 15:14
    
show the the time the last command was completed –  Pomario Apr 4 '12 at 15:16

1 Answer 1

up vote 2 down vote accepted

Something similar, but not exactly, what you ask: add the following lines to your ~/.bashrc

mytime() {
    printf '%*s**%s**\n' $((COLUMNS-13)) "" "$(date +%T)"
}
PROMPT_COMMAND=mytime

The difference is that the time is shown on the previous line, not the current.
I think it should be difficult to write on the current line without interfering with the shell prompt and line editing.

share|improve this answer
    
can you make it on the same line as the command was issued? –  Pomario Apr 4 '12 at 15:51
    
@Pomario: as I already said, I think it is difficult, which implicitly means that I don't know how. –  enzotib Apr 4 '12 at 15:53
2  
you can just use a carriage return instead of a newline in the printf command: mytime() { printf "%*s\r" $(tput cols) "$(date '+**%T**')"; } –  glenn jackman Apr 4 '12 at 17:00
    
@glennjackman: yeah, I tried this, and it doesn't work before. In any case, it get deleted as soon as you use the Backspace to delete a char. –  enzotib Apr 4 '12 at 17:20
    
Hmm, works for me. What's your $TERM? I have vt100 and xterm on a couple of machines. –  glenn jackman Apr 4 '12 at 17:28

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.