Ubuntu – Adding a tab and newline to the terminal prompt

command lineprompt

My terminal prompt is way too long. If I enter a long command, it gets wrapped to the next line which is hard to read.

I thought I'd take a page from ParrotOS and just have the commands entered on the line underneath the prompt.


Following this, I managed to get a newline added by going into ~/.bashrc and changing

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

to (note the \n at the end):

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\$ '

This works. The $ is on a newline now. The problem is, I'd also like to have it tabbed over a bit. I tried:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\t\$ '

But that prints out a time:

myName@myMachine:~/someDir
14:59:15$ 

Apparently \t is a timestamp placeholder in this context?

How can I just get a literal tab in there to be printed? I could of course just add spaces, but that isn't very clean.

Best Answer

According to the Bash manual there is no code for a horizontal tab, and \t displays the current time.

However, you can insert an arbitrary character into your prompt string by using \xxx where xxx is the octal ASCII code of the character. There is a Tab character for a horizontal tab, and its ASCII decimal code is 9. So you can get a horizontal tab in the prompt by inserting \011 (being the octal value of decimal 9) into your sequence.

Related Question