Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active February 12, 2024 14:52
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zulhfreelancer/9c410cad5efa9c5f7c74cd0849765865 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/9c410cad5efa9c5f7c74cd0849765865 to your computer and use it in GitHub Desktop.
How to add timestamp on right hand side of ZSH / iTerm2 terminal prompt?

Add the following snippet at the bottom of ~/.zshrc file.

Option 1 - Just time

RPROMPT='[%D{%L:%M:%S}] '$RPROMPT

Option 2 - Date and time

RPROMPT="[%D{%f/%m/%y} | %D{%L:%M:%S}]"

When you are done, run $ source ~/.zshrc to see the effect. If it doesn't work, quit iTerm2 and open it again.


Resources

@aslafy-z
Copy link

aslafy-z commented Apr 19, 2020

Thanks! It can be used in conjunction with https://stackoverflow.com/a/17915260 so the date stays fresh!

@chrisharrison
Copy link

H instead of L for 24 hour time.

@DanaKirsh
Copy link

nice, thanks!

@sudo-justinwilson
Copy link

Cheers!

@kedar2a
Copy link

kedar2a commented Feb 19, 2021

Great!

@dave-kennedy
Copy link

Just FYI, this doesn't have anything to do with iTerm2. It has its own timestamp feature that works independently of the shell prompt.

@xoxwgys56
Copy link

Thanks! and @chrisharrison that's what I want to

@Nassim-sadi
Copy link

Thank you , i added it to Custom Theme (Pi) and it worked also .

@swhasans
Copy link

swhasans commented May 5, 2023

Thanks!

@kotwanikunal
Copy link

RPROMPT="[%D{%m/%f/%y} | %D{%L:%M:%S}]" for the US date format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment