Skip to content

Instantly share code, notes, and snippets.

@catleeball
Last active June 28, 2019 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catleeball/49ffcbea41c50f2c26bdd45c8dc47482 to your computer and use it in GitHub Desktop.
Save catleeball/49ffcbea41c50f2c26bdd45c8dc47482 to your computer and use it in GitHub Desktop.
function git-cherry-pit {
# From https://sethrobertson.github.io/GitFixUm/fixup.html#remove_deep
# Removes a commit from git history, similar to using drop in rebase -i
if [ "$#" -ne 1 ]; then
echo "Usage: $ git-cherry-pit SHA"
fi
git rebase -p --onto $1^ $1
}
function pigball {
# Tarball given directory with pigz
if [ "$#" -ne 2 ]; then
echo "Usage: $ pigball /path/to/archive.tar.gz /data/to/tarball/"
fi
tar --use-compress-program="pigz --best --recursive" -cf $1 $2
}
function extract {
# Script v0.911 from https://github.com/xvoland/Extract/blob/master/extract.sh
# Slightly modified to modify IFS only inside the function, and to prefer
# pigz where possible.
SAVEIFS=$IFS
IFS="$(printf '\n\t')"
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar --use-compress-program="pigz" -xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) unpigz ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
IFS=$SAVEIFS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment