Skip to content

Instantly share code, notes, and snippets.

@brinchj
Created June 7, 2010 20:01
Show Gist options
  • Save brinchj/429103 to your computer and use it in GitHub Desktop.
Save brinchj/429103 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# Unpack in unique folder
dir=${1}_`uuid`;
mkdir ${dir};
tar vxf $1 -C ${dir};
# Move to working dir if only one folder unpacked
output=${dir};
if [ `find ${dir} -maxdepth 1|wc -l` -eq 2 ]; then
if [ `find ${dir} -maxdepth 1 -type d|wc -l` -eq 2 ]; then
_output=`find ${dir} -maxdepth 1`;
_output=`basename ${_output}`;
if [ -d ${_output} ]; then; else
output=${_output};
mv ${dir}/${output} .;
rmdir ${dir};
fi
fi
fi
echo "$1 was unpacked in ./${output}.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment