prwd - print reduced working directory
Fork me on GitHub

Print a reduced working directory for your prompt shell (PS1). The path can be shortened using any of the following:

  • aliases
  • max length and filler characters
  • newsgroup style

All of this is driven by your ~/.prwdrc file. prwd is also aware of your version control system, assuming it is either git or mercurial.

why?

The reason for prwd is that most shells read $PS1 differently and have a very rigid way to display the current working directory. prwd allows you to have one way to handle the display of your working directory and use it across multiple shells. It also allows you to keep an eye on your current branch when you enter a project handled by git or mercurial.

examples

# This is your prompt with a full path (no prwd):
belenos:/usr/local/lib/python3.3/multiprocessing/dummy$ echo "hello world"

# This is with: alias *py3k /usr/local/lib/python3.3
belenos:$py3k/multiprocessing/dummy$ echo "hello world"

# This is with: set maxlength 23
belenos:...ultiprocessing/dummy$ echo "hello world"

# This is with: set newsgroup on
belenos:/u/l/l/p/m/dummy$ echo "hello world"

# This is with: set cleancut on
belenos:.../dummy$ echo "hello world"

# This is with: set git on (assuming your branch is staging)
belenos:staging:~/projects/prwd$ echo "hello world"

download

Latest tarball: prwd-1.7.tar.gz (14K, signature)

GitHub: github.com/tamentis/prwd/
Fedora packages (by Christopher "cicku" Meng): apps.fedoraproject.org/packages/prwd
OpenPKG package: prwd-1.7-20130527.src.rpm (28K)

aliases

Defines a replacement name for a long path, for example, if you had the following line in your prwdrc:

alias *prwd /home/tamentis/projects/prwd

Then if you are in "/home/tamentis/projects/prwd/doc/html/", prwd would return "*prwd/doc/html". If you have spaces in your directories, you can wrap your 'alias' parameters with double quotes:

alias winDocs "/mnt/Windows XP/My Documents/"

max length

Defines the maximum length to return, the default filler string is "...", the default length is 32, a value of 0 will disable the feature all together.

set maxlength 20

This setting would turn "~/projects/prwd/doc/html" into a shorter string: "...cts/prwd/doc/html". You can define the filler string with the 'filler' variable:

set filler "-"

Or if your font/terminal/shell supports UTF, use an ellipsis:

set filler "…"

If you want prwd to keep complete path elements instead of cutting as much as possible, you can use this setting:

set cleancut on

newsgroup style

This will shorten the path by only displaying the first letter of each path components, toggle it with:

set newsgroup on

This will turn the "/home/tamentis/projects/prwd/src/nowhere" path into "/h/t/p/s/nowhere". Note that the newsgroup style filter is applied before the path is trimmed with 'maxlength'.

git & mercurial

You can see the currently selected branch as a prefix to your path whenever you are in a git/mercurial repository, enable this feature with the following options:

set mercurial on
set git on

The resulting path will be "my-branch:project/folder" if you are located on the HEAD of a branch, it will be "59cefd9...:project/folder" if you are anywhere else (git only).

install

$ ./configure
$ make
$ sudo make install

setup

This will depend on your shell, but in general the following will do:

export PS1='\h:`prwd`\p '

Note that the single quote matters since you want to keep the command within the variable as-is (unresolved).

Bertrand Janin <b@janin.com> · Powered by Python, OpenBSD, a teashpoon of WTF & the spirit of the UNIX gods.
This page was last updated: 2013-05-25