Add newline to Oh My ZSH Theme

How about this

NEWLINE=$'\n'
PROMPT='%n ${NEWLINE} $ '

Here is my version which works just like the others, but repeats the last symbol of the previous line so that it imitates the exact prompt that agnoster gives you:

prompt_end() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  else
    echo -n "%{%k%}"
  fi
  echo -n "\n%{%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{%f%}"
  CURRENT_BG=''
}

Note: If you do not want to modify the library's source code, you can also just put this function into your ~/.zshrc file near the end. It will then be used over the library-provided function.

enter image description here


I think the proper place to change one's prompt is in the theme itself. On my system, it's in ~/.oh=my-zsh/themes/agnoster.zsh-theme. I added a \n➜ there:
Find this section:

# End the prompt, closing any open segments

prompt_end() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n " % 

{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  else
    echo -n "%{%k%}"
  fi
  echo -n "\n➜%{%f%}"
  CURRENT_BG=''
}

I was actually searching for the same answer. But my needs was a little more specific since I only wanted to add a newline in the agnoster theme, the one I'm using now.

In my research, I find a lot of forked themes that already do it, but I thought that this was an overkill solution for only add a new line.

So I read the agnoster code and come up with this simple solution of overwrite the prompt_end() function in my .zshrc file.

To do it, just add the code bellow in your .zshrc file:

prompt_end() {
  if [[ -n $CURRENT_BG ]]; then
      print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  else
      print -n "%{%k%}"
  fi

  print -n "%{%f%}"
  CURRENT_BG='' 

  #Adds the new line and ➜ as the start character.
  printf "\n ➜";
}

Hope it helps you to have a clue on how to customize your chosen theme.

Here is the result:

enter image description here

Tags:

Zsh

Oh My Zsh