73

I'm trying to find the PS1 variable in oh-my-zsh and change it so iTerm doesn't look as clogged up. Running the following command:

echo $PS1

gives me this

%{%f%b%k%}$(build_prompt)    

Additionally, I've attempted to edit the .zshrc file and put

export PS1="random-text"

but it didn't work. I've tried to look around for the PS1 variable, but couldn't locate it.

If it also helps, I'm running El Capitan on my laptop right now. I couldn't find any similar questions to what I posted so any help would be greatly appreciated.

Daniel Dao
  • 830
  • 1
  • 7
  • 11
  • For answers about the macOS Catalina zsh look here: https://stackoverflow.com/a/58563434/990971 – efkah Nov 26 '19 at 22:04
  • 1
    Questions about configuring your shell _as a user_ rather than as a developer are generally more on-topic at [unix.se] or [Super User](https://superuser.com/). – Charles Duffy Jun 30 '21 at 22:14
  • If like me you ended up here because you need to show the virtual env in Python, the just change your theme in `~/.zshrc` to the following: `ZSH_THEME="kennethreitz"` :-) – coccoinomane Nov 18 '22 at 11:46

2 Answers2

93

Changing your Theme:

To edit your prompt in oh-my-zsh you need to edit a PROMPT variable in your theme instead of PS1. In your .zshrc file you will find a line that looks something like this:

ZSH_THEME="themename"

oh-my-zsh stores these themes in the ~/.oh-my-zsh/themes folder. If you ls ~/.oh-my-zsh/themes you will see a list of themes that you can change. The above theme would be named themename.zsh-theme in this directory.

Customizing your Theme:

If you want a simple way to customize your oh-my-zsh theme you can copy a file already in this theme folder and edit that.

To change your prompt simply edit the PROMPT variable. For example:

PROMPT=">>"

This would make two >'s your prompt.

I like editing the already existing simple theme. the simple.zsh-theme file looks like this:

PROMPT='%{$fg[green]%}%~%{$fg_bold[blue]%}$(git_prompt_info)%{$reset_color%} '

ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" ✗"
ZSH_THEME_GIT_PROMPT_CLEAN=" ✔"

Applying the Changes:

Now just change the theme in your in your .zshrc file:

ZSH_THEME="simple"

And reload oh-my-zsh with:

. ~/.zshrc
Simson
  • 3,373
  • 2
  • 24
  • 38
Caleb Adams
  • 4,445
  • 1
  • 26
  • 26
  • 2
    To create a new theme, it should be added to the [`~/.oh-my-zsh/custom/themes/` directory](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-and-adding-themes) – Devin May 29 '19 at 21:22
  • 1
    Added to @Devin comment above, here is the official doc about "Overriding and adding new themes" https://github.com/ohmyzsh/ohmyzsh/wiki/Customization – onelaview Dec 10 '19 at 02:35
  • You don't need any theme. Just in file `.zshrc` add `PROMPT='%. $ '` It should do the work. – Pavol Travnik Feb 10 '21 at 14:01
  • `I like editing the already existing simple theme`: you do not explain how you edit it. Or do you mean edit your `prompt` by using the `simple theme`? You could also write where to put the `theme` variable in the `.zshrc`. – Timo Jun 15 '21 at 18:15
11

Important update 1st July, 2021. I saw devote for this answer from yesterday. So the below command might not work anymore. Just try POWERLEVEL10K now.

For POWERLEVEL9K if you're using it

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)

PS: Try POWERLEVEL10K, it's much better. trust me

Alvin Smith
  • 547
  • 5
  • 9