Skip to content

Instantly share code, notes, and snippets.

@Qix-
Last active August 29, 2015 14:14
Tup Breakout Script
#!/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