I want to be able to launch a terminal emulator (preferably gnome-terminal) with interactive zsh running inside using a custom prompt string. I don't want to modify my default prompt string in .zshrc because I use that most often and it is just occasionally I want to launch a terminal with a custom zsh prompt string (more specifically, I want the time to show up in the right hand side prompt).

If I already have a terminal window open, I can solve this by running:

export RPS1=%T zsh

But I can't figure out the syntax for making this work together with launching a new terminal instance. This is what I have tried with the error message below each command:

gnome-terminal -- export RPS1=%T zsh
# Error: Failed to execute child process “export” (No such file or directory)
gnome-terminal -- sh -c export RPS1=%T zsh
# Prints all the options, like with `set`
# and then exits with "The child process
# exited normally with status 0".
gnome-terminal -- sh -c "export RPS1=%T zsh"
# The child process exited normally with status 0.
gnome-terminal -- sh -c "export RPS1=%T; zsh"
# This start the terminal with zsh, but the RSP1 is not changed

I considered reading a custom rc file, like in this answer, but there does not seem to be a way of doing this in zsh without using source, which was giving me similar problems as above.


2 Answers 2


In zshrc, allow for overriding RPS1 by setting it as:

# If rps1 is not set, use a default value
RPS1=${rps1-"Your usual RPROMPT"}
  • Now you can launch a command with a different RPS1 by setting rps1 in its environment, for example:
rps1=%T gnome-terminal
  • The parameter expansion form ${param-word} allows RPS1 to be set to null:
rps1= gnome-terminal

Parameters used by the shell (such as RPS1) needn't be exported. They are used to set up the shell, so should be set once in the rc file.

If a program (e.g. gnome-terminal) is launched with rps1 in its environment, any subsequent programs launched from it will see rps1 in their environment. To avoid this, either of the following could be added to zshrc: unset rps1 (after using it to set RPS1) or typeset +x rps1.

BTW, the following will export two shell variables:

export RPS1=%T zsh
  • The above is export with two arguments, resulting in RPS1=%T & zsh='' being created in the environment
  • To set RPS1 in the current shell, simply do:
  • Thanks! I did not know about using a default variable value like that, neat! My RPS1 is usually set by an extension via oh-my-zsh, so I have put the following line after sourcing oh-my-zsh in .zshrc: RPS1=${custom_rps1-$RPS1}. Then I can launch a new terminal with a custom prompt via gnome-terminal -- sh -c 'custom_rps1="%T" zsh'. Apr 26, 2020 at 5:03
  • How is your answer different than the one I provided earlier? Apr 26, 2020 at 17:09

When you run the shell, it's processing your /~.zshrc, which is overwriting the prompt.

One option would be to do something like this in your ~/.zshrc:

MY_PROMPT="${MY_PROMPT:-"> "}" # Set the value to "> " if it isn't currently set

Then, if you start a shell, you'll get:

> MY_PROMPT="my new prompt > " zsh
my new prompt >

Note here that it's important that I chose a non-standard variable (here MY_PROMPT) since standard variables might already contain default values before the shell processes your ~/.zshrc.

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.