Skip to content

Instantly share code, notes, and snippets.

@beenotung
Created July 15, 2019 05:04
Show Gist options
  • Save beenotung/c729c06ac7c4392eaf74469c3dee8ca7 to your computer and use it in GitHub Desktop.
Save beenotung/c729c06ac7c4392eaf74469c3dee8ca7 to your computer and use it in GitHub Desktop.
#!/bin/bash
## extract files archived from git-compress
## TODO use tmp folder to support operation within a git repo
set -e
set -o pipefail
with_progress=0
filename=''
if [ "$1" == "-p" ] || [ "$1" == "--progress" ]; then
with_progress=1
filename="$2"
elif [ "$2" == "-p" ] || [ "$2" == "--progress" ]; then
with_progress=1
filename="$1"
else
filename="$1"
fi
if [ ! -f "$filename" ]; then
echo >&2 "File $filename not found!"
exit 1
fi
if [ -d .git ]; then
echo "Error: this directory is already a git repo"
exit 1
fi
if [ $with_progress == 1 ]; then
echo "extracting $filename,"
tar xz --checkpoint-action="echo=%T" -f "$filename"
echo "extracted $filename,"
echo "git checking-out,"
else
tar xzf "$filename"
fi
git checkout .
rm -rf .git
echo "extraction done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment