Bash’s $PS1 variable is what you see every time you get a prompt. It’s there, waiting for you to type something.
Some people go minimal … maybe just “$” like the Bourne shell. Others go crazy and cram as much information as possible … on multiple lines … in colors.
My $PS1 falls somewhere in the middle, but I realized today it was time for a change. One of the things I wanted was the current path. A lot of people like to put that in the “xterm title bar”, but I wanted it closer to the action.
After a bit of experimentation, I found that I could play with the PROMPT_COMMAND to faux-position the path in pale gray ON the same line as the prompt.
Here’s my variables.sh file which I put under ~/etc/bash/local/ — it works with the rest of my config files:
printf “\e[30;40;1m%*s\n\e[0m\e[1A“ $COLUMNS “$PWD“
export FIND_OPTIONS=”-name .git -prune -o -name .hg -prune -o“
The prompt_command function uses “printf” to print ($COLUMNS wide) the $PWD. There are escapes sequences to color it gray. Finally, the “\e[1A” sequence moves the cursor 1 line up. Consequently, the prompt itself prints on the same line as the PROMPT_COMMAND.
It looks something like:
What do you put in your $PS1?