Running the following line from the command will add a blank line before your command line prompt.
PS1=$'\n'"$PS1"
Make this Change Permanent
To make this change permanent add this line to your .bashrc
(or .zshrc
if you’re using Z shell).
Example
Before the Change
sal@salcode:~/wp-cli (master)$ ls
CONTRIBUTING.md features
LICENSE php
README.md phpcs.xml.dist
VERSION phpunit.xml.dist
bin templates
ci tests
composer.json utils
composer.lock vendor
sal@salcode:~/wp-cli (master)$ ls
After the Change
sal@salcode:~/wp-cli (master)$ PS1=$'\n'"$PS1"
sal@salcode:~/wp-cli (master)$ ls
CONTRIBUTING.md features
LICENSE php
README.md phpcs.xml.dist
VERSION phpunit.xml.dist
bin templates
ci tests
composer.json utils
composer.lock vendor
sal@salcode:~/wp-cli (master)$ ls
zsh specific solution
Thanks to my co-worker Amor Kumar for pointing out this zsh specific solution that eliminates the empty line at the top of a new shell.
Add the following to ~/.zshrc
precmd() {
precmd() {
echo
}
}
In zsh, precmd is a hook “Executed before each prompt.”
This clever piece of code defines a function called precmd()
. When the function is run the first time, it (re)defines the function precmd()
to echo
a blank line. During this first run, it does NOT output anything.
In other words, the first time precmd()
runs (at the top of a new shell), it does NOT output anything but it does redefine itself so on all subsequent runs it outputs a blank line.
Leave a Reply