Zsh new line after each command

Can I customize my prompt to display a new line after each command?

To give an example. In the following screenshot, I ran cat .zshrc . I want to have a new line between the last output line of the command . ~/.zsh_aliases . ~/.zsh_aliases and ~ $ .

enter image description here

+8
zsh zsh-zle
source share
6 answers

Modify ~/.zshrc and add the string precmd() { print "" } . This will simply print an empty line before rendering PROMPT.

+18
source share

I know this is a bit outdated, but I found a way, even if it is not very clean, I just wanted to share it:

 function precmd { if [[ "$NEW_LINE" = true ]] then if [[ "${ADD_NEW_LINE}" = true ]] then PROMPT=$'\n'"${PROMPT}" ADD_NEW_LINE=false fi else PROMPT="${PROMPT}" NEW_LINE=true ADD_NEW_LINE=true fi } 

Hope this helps

+2
source share

Another way is to simply set up a custom prompt in ~/.zshrc that includes a newline. For example:

 autoload -Uz promptinit promptinit PROMPT=" % n@ %m:%~ $ " 
+2
source share

The accepted answer (by @ abid-h-mujtaba) always prints a new line even when the shell is first loaded. I submitted changes that were not accepted for any reason.

This is what I use in my personal dot files (see "Window Configuration" in zshrc ):

 function precmd() { # Print a newline before the prompt, unless it the # first prompt in the process. if [ -z "$NEW_LINE_BEFORE_PROMPT" ]; then NEW_LINE_BEFORE_PROMPT=1 elif [ "$NEW_LINE_BEFORE_PROMPT" -eq 1 ]; then echo "\n" fi } 
+2
source share

The following works:

PS1 export = '
Another text is blah $ '

0
source share

Using zsh with oh-my-zsh, git support, and ZSH Powerlevel9k Theme on Ubuntu 18.04 installed as described here: https://linuxhint.com/install_zsh_shell_ubuntu_1804/

To get a hint on a new open line:

/usr/share/powerlevel9k/powerlevel9k.zsh-theme

Look for the left_prompt_end () function

The function is as follows:

 # End the left prompt, closes the final segment. left_prompt_end() { if [[ -n $CURRENT_BG ]]; then echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" else echo -n "%k" fi echo -n "%f$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" CURRENT_BG='' } 

Just add one newline command. The function should now look like this:

 # End the left prompt, closes the final segment. left_prompt_end() { if [[ -n $CURRENT_BG ]]; then echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')\n" else echo -n "%k" fi echo -n "%f$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" CURRENT_BG='' } 

The following line has been changed from:

 echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" 

In order to:

 echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')\n" 

Tell me on a new line: enter image description here

0
source share

All Articles