Toly
Toly

Reputation: 45

How to display time in terminal prompt,using PS1 variable?

As we all know, we can modify the "PS1" variable to change the prompt of our terminal on Linux or MAC OS, I have changed "PS1" variable to
PS1="\[\033[0;37;40m\u@\033[0;36;40m\h:\033[0;35;40m\w$\033[0m^.^\t \]", and my prompt of terminal can display like this.

enter image description here

the time will be updated after I press "enter" button, now I want to let the time string can update automatically in a single line.How can I do this?I use bash.

Upvotes: 0

Views: 1086

Answers (1)

GioLaq
GioLaq

Reputation: 2547

If you are using zsh shell edit ~/.zshrc adding the following lines:

setopt PROMPT_SUBST
PROMPT='%B%F{red}%n@%m%f%F{yellow}[%D{%L:%M:%S}]%f:%F{blue}${${(%):-%~}}%f$ %b'
TMOUT=1

TRAPALRM() {
    zle reset-prompt
}

Save and then update your terminal with source .zshrc

Upvotes: 1

Related Questions