Is Your Bash Prompt Cramping Your Style?
It is sometimes hard to form a mental model of a directory tree when working with the command line. GUI shells tend to provide more visual cues. For example, in OS X, the Finder has a column view that allows you to quickly see how directories are nested.
So, like a lot of Bash users, I used to get around this by printing the current working directory in my shell prompt:
However, things can get pretty cramped when dealing with deeply nested directories. A better solution is needed. Ideally, I want a minimal prompt that just displays my user@host. I only need to get my bearings when I’m moving around in the directory tree. Therefore, I’ve come up with the following.
The current working directory is printed after every cd. This allows me to get my bearings when I need to, while keeping my Bash prompt short and sweet. The following incantation in ~/.bashrc does the trick:
# Print working directory after a cd.
cd() {
if [[ $@ == '-' ]]; then
builtin cd "$@" > /dev/null # We'll handle pwd.
else
builtin cd "$@"
fi
echo -e " \033[1;30m"`pwd`"\033[0m"
}
Have you come up with other solutions for longpromptitis? Let me know in the comments!