Skip to content

Instantly share code, notes, and snippets.

@jashezan
Last active June 2, 2022 20:12
Show Gist options
  • Save jashezan/0ab65c87a76d2f78225de11b3ed3e1e8 to your computer and use it in GitHub Desktop.
Save jashezan/0ab65c87a76d2f78225de11b3ed3e1e8 to your computer and use it in GitHub Desktop.
Show time and date in terminal. You can show time & date in right side of the terminal. You should have ZSH shell and oh-my-zsh to use this.

Show Time and Date in the Terminal

Show time and date in the terminal. You can show the time and date on the right side of the terminal. You should have a ZSH shell and oh-my-zsh to use this.

Add this into ~/.zshrc above source ~/.zshrc line for ZSH shell to show time & date on the right side of the terminal.

RPROMPT='${ret_status}%{$fg[green]%}~ %{$fg_bold[black]%}$(git_prompt_info)%{$bg[yellow]%}%{$fg[black]%} %D{%a, %f %b %Y} %{$bg[red]%}%{$fg[white]%}%D{ %L:%M:%S %p} % %{$reset_color%}'

Image preview:

only-time-and-date

Full image:

full

[Note: I am using Kali Linux with oh-my-zsh (agnoster theme) on ZSH shell in Windows Terminal WSL.]

You can change all the colors shown in the picture. change them in bg and fg. bg = background, fg = foreground .

See more about supported color

You can edit time and date format by changing them after %D .
Some Time format:

 %D     The date in yy-mm-dd format.
 %T     Current time of day, in 24-hour format.
 %t %@  Current time of day, in 12-hour, am/pm format.
 %*     Current time of day in 24-hour format, with seconds.
 %w     The date in day-dd format.
 %W     The date in mm/dd/yy format.
 %D{strftime-format}

See More about Time format

If you want this on left side, then just write PROMPT instead of RPROMPT .

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