I am trying to set PS1
so that it prints out something just right after login, but preceded with a newline later.
Suppose export PS1="\h:\W \u\$ "
, so first time (i.e., right after login) you get:
hostname:~ username$
I’ve been trying something like in my ~/.bashrc
:
function __ps1_newline_login {
if [[ -n "${PS1_NEWLINE_LOGIN-}" ]]; then
PS1_NEWLINE_LOGIN=true
else
printf '\n'
fi
}
export PS1="\$(__ps1_newline_login)\h:\W \u\$ “
expecting to get:
# <empty line>
hostname:~ username$
A complete example from the the beginning would be:
hostname:~ username$ ls `# notice: no empty line desired above!`
Desktop Documents
hostname:~ username$
__ps1_newline_login
runs only–once, but not every time? For example__git_ps1
uses this exact same technique to set every prompt not just initially. – Hairstyle"$(__git_ps1)"
and not'$(__git_ps1)'
? The quotes make all the difference. If it actually does use double quotes, it would have toecho '$(foo)'
in order to place a literal string'$(foo)'
in the prompt, which can then be subsequently expanded. – Robertoroberts$(__git_ps1)
with double quotes, and it seems to be working... – Hairstyle