Last active
August 29, 2015 14:14
-
-
Save Qix-/2088d1bf8097dc55ff34 to your computer and use it in GitHub Desktop.
Tup Breakout Script
This file contains hidden or 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 | |
# Takes a **RELATIVE** path and makes it relative to the *actual* source tree. | |
# Only use if you know what you're doing; this circumvents what Tup is supposed | |
# to do: manage read/write access. | |
# Check that we're in a tup directory | |
test "$(pwd | grep "\/\.tup")" || (echo "Not in a .tup directory!" 1>&2 && exit 1) | |
# First, find the actual root. | |
troot= | |
cur="$(pwd)" | |
while true; do | |
if [[ "$(basename "$cur")" == ".tup" ]]; then | |
troot="$(dirname "$cur")" | |
break | |
else | |
cur="$(dirname "$cur")" | |
fi | |
done | |
# Second, find the sub directory relative to the tup directory | |
relpath(){ python -c "import os.path; print os.path.relpath('$1','$2')" ; } | |
# Third, get the *actual* directory by killing off the tup prefix and | |
# echo it out as an absolute path | |
relpath "$(pwd)" "$troot" | cut -d "/" -f4- | xargs -I% echo "/%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment