path-shrinker is a command to shrink directory path like this.
$ path-shrinker -short -last -tilde /Users/oinuma/go/src/github.com/oinume/path-shrinker
~/g/s/g/o/path-shrinker
You can download a binary from GitHub.
Define PS1
in your .bashrc or .bash_profile.
PS1='$(path-shrinker -fish) $ '
Then your terminal will show a prompt like this:
~/g/s/g/o/path-shrinker $ pwd
/Users/kazuhiro/go/src/github.com/oinume/path-shrinker
For this directory tree:
/home/
me/
foo/
bar/
quux/
biz/ # The prefix b is ambiguous between bar and biz.
Here are the results of calling path-shrinker <option> /home/me/foo/bar/quux
:
Option Result
<none> /h/m/f/ba/q
-l|--last /h/m/f/ba/quux
-s|--short /h/m/f/b/q
-t|--tilde ~/f/ba/q
-f|--fish ~/f/b/quux