As a hardcore linux user, I frequently use the bash shell. As a developer I often have directories with long names, often with many subdirectories.
The problem I was encountering was that the CWD displayed in my
$PS1 prompt was so long that I couldn’t fit longer commands without reaching the end of the line. With this in mind, I had two options: Modify
$PS1 so that it looked like this:
Personally, I don’t like this. I prefer to have everything on one line. So I came up with an alternative based on an old script (which I would link to here but do not recall where I found it):
Still display the CWD in the prompt, but abbreviate it.
pwdshort was born.
pwdshort takes the output of the environment variable
$PWD and removes most of the directory names, replacing them with an ellipsis. It keeps the first and last directory names (which is configurable), resulting in a much shorter CWD output.
As you can see, it still lets you know where you are, but eliminates unnecessary data. In addition, another useful feature is the ability to replace the output directory names with something else, i.e., instead of “/templates/”, it could output “/tpl/”. This is all done in the configuration file as well,
Using directory name replacement, we could shorten the PWD even more, resulting in something like:
As of this article, the current version is
To use this project in your bash shell, see the instructions
README.md file in the GitHub project.
pwdshort project on GitHub.