Skip to content

Instantly share code, notes, and snippets.

@Pyrolistical
Created December 26, 2011 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pyrolistical/1520361 to your computer and use it in GitHub Desktop.
Save Pyrolistical/1520361 to your computer and use it in GitHub Desktop.
contextural pwd - shows at most the grandparent of the current directory
#!/bin/bash
nicepwd=`pwd | sed "s|$HOME|~|"`;
# count the number of slashes in pwd
slashes=`pwd | perl -pe 's/[^\/]//g' | wc -m`
if [ $slashes -le 2 ]; then
echo "$nicepwd";
else
# using a delimiter of / from the ${slashes}th field keep the remain to end of pwd then trim leading / if it exists
pwd | cut -f $slashes- -d / -s | perl -pe 's/^\///g'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment