Skip to content

Instantly share code, notes, and snippets.

@tmichel
Last active January 17, 2018 09:34
Show Gist options
  • 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