Skip to content

Instantly share code, notes, and snippets.

@robhurring robhurring/examples.txt
Last active Feb 5, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.