zsh agnoster theme chagne prompt/ps1

8.2k Views Asked by At

How can I change the prompt of my zsh shell while still retaining the cool coloring that agnoster provides? For people who don't know, it looks like this enter image description here I want to add some things like ! and \u before the working directories. I've tried the usual PS1="! \u \w" but it just gives this: enter image description here

EDIT: I found the right escaped characters for inserting information, but it cancels out the styling enter image description here How can I change the prompt while maintaining the styling?

2

There are 2 best solutions below

0
On

You can change the prompt_context() in .oh-my-zsh/themes/.zsh-theme with the following block of code

prompt_context() {
     if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
         prompt_segment black default "%(!.%{%F{yellow}%}.)~"
     fi
}
0
On

You'd have to customise the theme, i.e. .oh-my-zsh/themes/agnoster.zsh-theme, add your own function to the build_prompt function and add whatever you need to the prompt:

## Main prompt
build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
  prompt_context
  prompt_dir
  prompt_git
  prompt_hg
  prompt_end
}

I personally added a prompt_custom stub, which I then replace with the real prompt function in my .zshrc, so I only have to maintain that small customisation (probabaly worthty of a pull request at some stage...)

prompt_custom() {
}