I'm trying to add a newline to my existing Oh My ZSH theme but can't figure out what to add or where it should be added / changed. Any ideas?
6 Answers
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:

- 1,687
- 2
- 17
- 20
-
11Very nice work. Just what I was looking for. Thank you! – rp. Oct 29 '18 at 03:11
-
When i do this, my cursor alignment goes off :/ Like it is moved a bit to the left. Anyone else with a similar issue? – emin Jan 20 '20 at 19:04
-
3Seems like I had issues getting this to work, and believe moving this override to after "source $ZSH/oh-my-zsh.sh" fixed it. – Ethan Knowlton Aug 10 '20 at 18:18
-
Nice work, thank you I was looking for this – Wooz12345 Jul 23 '22 at 07:06
-
does this work for the default `robbyrussell` theme? – jcollum Mar 06 '23 at 23:37
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=''
}

- 30,962
- 25
- 85
- 135

- 550
- 5
- 11
-
The code formatter in stackoverflow seems difficult. I'm sorry for the badly formatted code. Is there a limit to how much code can be formatted as code? – Micheal Bee Nov 28 '19 at 20:36
-
3When you change the theme directly, you will loose your config when update it. – gvsrepins Feb 17 '20 at 12:48
-
2Although I'll stick with the "override in `.zshrc`" approach. It's still very helpful to remind people to look into the original theme file, learn how the `prompt_end` is implemented and know what to override and where to append. Thanks! – Escape0707 Apr 27 '20 at 02:13
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.

- 13,664
- 17
- 79
- 131
If you don't want to update your agnoster theme because it will be overwritten by an update, you can create a new theme and place it under ~/.oh-my-zsh/custom
directory. The "custom" directory is excluded by git.

- 23
- 4
If your using PROMPT
and appending to it, like in senpai theme, just do:
if [[ $SENPAI_SHOW_K8S == true ]]; then
PROMPT+="\$(k8s_info)
${yellow} —————» %f"
fi
And you'll get a multiline prompt:
[19:28:02] ~ ⎈:default-demo2-gke
—————» ns:default ❯ ls /etc
Simplified:
PROMPT='multi
line
prompt'

- 3,275
- 1
- 18
- 30