-
-
Save Pyrolistical/1520361 to your computer and use it in GitHub Desktop.
contextural pwd - shows at most the grandparent of the current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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