Skip to content

Instantly share code, notes, and snippets.

@tmichel
Last active January 17, 2018 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmichel/78c71adbdc1b94a726389ac9d2fe91b6 to your computer and use it in GitHub Desktop.
Save tmichel/78c71adbdc1b94a726389ac9d2fe91b6 to your computer and use it in GitHub Desktop.
Abbreviated path: keeping first letter of parent dirs
#!/bin/sh
# Print $PWD where parent directories are abbreviated to their first letters.
# $HOME is replaced with ~.
# Based on: https://unix.stackexchange.com/a/26885
sed -e "s:$HOME:~:" -e 's:\([^/]\)[^/]*/:\1/:g' <<<$PWD
# PWD=/home/me/foo/bar/baz
# => ~/f/b/baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment