Add Timestamp To Oh-my-zsh Robbyrussell Theme


Answer :

According to the zshmisc man page there are several % codes for date and time, eg:

 %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} 

The last one allows codes listed in the strftime(3) man page. Edit your ~/.zshrc file and add at the end a new PROMPT value, eg:

 PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} %D %T % %{$reset_color%}' 

If you want add date/time to the right, you set RPROMPT

local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' RPROMPT="[%D{%y/%m/%f}|%@]" 

enter image description here


I added this %D{%m/%f/%y}|%D{%L:%M:%S} to the main theme to display the date and time as mm/dd/yy | hh:mm:ss.

So here is the full command I use:

PROMPT='%D{%m/%f/%y}|%D{%L:%M:%S} ${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}${NEWLINE}$ ' 

Which gives:

enter image description here


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable