Skip to content

Instantly share code, notes, and snippets.

@robhurring
Last active February 5, 2016 15:14
Show Gist options
  • Save robhurring/d9f26da9db56f3f84912 to your computer and use it in GitHub Desktop.
Save robhurring/d9f26da9db56f3f84912 to your computer and use it in GitHub Desktop.
shortenpath for zsh/bash
/u/local: pwd b3bb610
/usr/local
~/P/proccli: pwd master da99d97 2↓ ✽
/Users/rob/Projects/proccli
# vim-like shortenpath() function
# modified from http://stackoverflow.com/questions/25945993/how-to-get-a-vim-tab-like-short-path-in-bash-script
shortenpath() {
print -n "${1}" | sed -e "s|${HOME}|~|" -e 's:\(/*\)\([^\.]\)[^/]*/:\1\2/:g'
}
shortenpath "$(pwd)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment