gusl: (Default)
[personal profile] gusl
Is there a way to make my shell show the date&time every time I get the prompt?

This would make it easy to measure how long things took, even before you suspect anything.

(no subject)

Date: 2007-09-06 04:11 pm (UTC)
From: [identity profile] dachte.livejournal.com
If you're using bash, the following might be a start:

PS1="\D{%d-%m-%y--%H-%M-%S} $ "

(no subject)

Date: 2007-09-06 04:12 pm (UTC)
From: [identity profile] dachte.livejournal.com
Err.. I mean:
PS1="\D{%d-%m-%y--%H:%M:%S} $ "

But then, the dashes and colons are all replaceable with whatever you like.

(no subject)

Date: 2007-09-06 04:51 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
It works! Thank you! This is great.

(no subject)

Date: 2007-09-06 04:54 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
I kinda like: PS1="bash(\D{%d-%m-%y, %H:%M:%S}) $ "

resulting in: bash(06-09-07, 12:53:51) $

(no subject)

Date: 2007-09-06 06:28 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
Is there a way to make one's scripts hit "enter"? It would be good to do this as the first thing, in order to "start the clock".

I suppose I can always add a line like "echo", but that's not exactly the same thing.

(no subject)

Date: 2007-09-06 07:22 pm (UTC)
From: [identity profile] en-ki.livejournal.com
Are you aware of the "time" builtin command?

(no subject)

Date: 2007-09-06 07:43 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
oh, of course.

OTOH, it's better to not have to add anything to your scripts.

(no subject)

Date: 2007-09-07 12:46 am (UTC)
From: [identity profile] wjl.livejournal.com
except for the "pressing enter" part? :)

(no subject)

Date: 2007-09-07 01:26 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
well, that's rather easy to do outside of the script.

In any case, I'm worrying that "echo" will not give you a prompt inside of the script... You only get one when the script to actually finishes...

(no subject)

Date: 2007-09-07 02:19 am (UTC)
From: [identity profile] wjl.livejournal.com
Yeah, "echo" will not do what you want. But if there were something that did do what you want, it would be no easier to do outside of the script than running "time"... unless i'm missing something obvious.

(no subject)

Date: 2007-09-07 04:42 pm (UTC)
From: [identity profile] inferno0069.livejournal.com
In zsh you can define a function preexec() that runs after you hit enter to run a command but before the command runs; it could print the time. Then you could either keep the time in your prompt or define precmd() to print it just before the prompt. I don't know which other shells have this, but I wouldn't be surprised if bash were among them.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags