Views:
276,958
Votes: 2
Tags:
command-line
bash
bashrc
prompt
ps1
Link:
🔍 See Original Answer on Ask Ubuntu ⧉ 🔗
URL:
https://askubuntu.com/q/1165407
Title:
How can I shorten my command line (bash) prompt?
ID:
/2019/08/13/How-can-I-shorten-my-command-line-_bash_-prompt_
Created:
August 13, 2019
Edited: August 13, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
I wrote a function you can modify to suit your needs:
function termprompt() {
PS1="${PS1//@\\h/}" # Remove @host
PS1="${PS1//\\w/\\W}" # Change from full directory to last name
}
Place this function at or near the bottom of ~/.bashrc
after the PS1
line has been fully computed.
You would type termprompt
whenever you wanted to shorten your prompt or, have termprompt
called from the bottom of your ~/.bashrc
for permanency.
The advantage of this technique over many other answers is .bashrc
can setup PS1
in four different ways (xterm+no-color, xterm+color, no-xterm+no-color, no-xterm+color). This answer supports all four current methods and probably future methods too.
Another advantage is this method has less complex control codes to traverse over in order to insert your changes.