Skip to content

Instantly share code, notes, and snippets.

@frebib
Last active July 3, 2018 19:33
Show Gist options
  • Save frebib/2b4ba154a9d62b31b1edcb50477e7f01 to your computer and use it in GitHub Desktop.
Save frebib/2b4ba154a9d62b31b1edcb50477e7f01 to your computer and use it in GitHub Desktop.
Pretty-pwd, from the fish shell, in POSIX sh
#!/bin/sh
set -e -o pipefail
# This sed expression is POSIX compliant and provides 99.9% the same functionality as the previous revision
# The only caveat is with paths that contain % (percent) characters. This can be changed for # or something else if desired
pwd | sed -E 's|^'$HOME'|~|;s|(.*)/|\1%|;s|((^\|/)\.?[^/%]{1})[^/%]*|\1|g;s|(.*)%|\1/|'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment