bash - How to set a conditional newline in PS1? -
i trying set ps1 prints out right after login, preceded newline later.
suppose export ps1="\h:\w \u\$ ", first time (i.e., right after login) get:
hostname:~ username$ i’ve been trying in ~/.bashrc:
function __ps1_newline_login { if [[ -n "${ps1_newline_login-}" ]]; ps1_newline_login=true else printf '\n' fi } export ps1="\$(__ps1_newline_login)\h:\w \u\$ “ expecting get:
# <empty line> hostname:~ username$ a finish illustration the origin be:
hostname:~ username$ ls `# notice: no empty line desired above!` desktop documents hostname:~ username$
try following:
function __ps1_newline_login { if [[ -z "${ps1_newline_login}" ]]; ps1_newline_login=true else printf '\n' fi } prompt_command='__ps1_newline_login' export ps1="\h:\w \u\$ " explanation:
prompt_command special bash variable executed every time before prompt set. you need utilize -z flag check if length of string 0. bash shell ps1
No comments:
Post a Comment