1

I would like to edit my shell prompt to display time. I am currently using zsh, though I would like the customize the shell prompt to show time.

I understand that an echo $PS1 will give me the environment variable contents. Given:

[%n]%~

Setting the prompt using:

setenv PROMPT '[%n]%t ' 

I also know if I type man zsh and press enter it will give me a list of formats I can change to.

  • setenv is a csh command. You should get a "command not found" error in zsh. – chepner Jun 19 '15 at 13:32
4

I think you want to do:

PROMPT='[%n]%t '

setenv is a csh command. The equivalent in Bourne-like shell would be export, but here you don't want to export that variable to the environment, just define the $PROMPT shell variable (typically in your ~/.zshrc).

Try man zshmisc and look for the section "SIMPLE PROMPT ESCAPES" (or run info zsh 'prompt expansion') to see all of the escape-sequences available. Also, take a look at zsh's RPROMPT variable. It can be useful and fun.

| improve this answer | |
  • I read the RPROMPT is good for displaying time as well, it shows on the right side of the terminal or screen right? – Juan Davila Jun 19 '15 at 16:05
  • I decided on bash, which I could add time by setting the environment variable, PS1="\s-\v-\t\$" though strange, the prompt does not allow me to type on the same line as the prompt, actually below it. – Juan Davila Jun 25 '15 at 19:57
  • Also, what you have suggested also works. – Juan Davila Jun 25 '15 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.