Commit e5d280f3 authored by Robert Labudda's avatar Robert Labudda
Browse files

x and pack

parent 5be6e838
Utils
=====
* **x** - autodetect the archive format and extract it here
* **pack** - compress files and folders efficiently and without big parameter dances
* **dpass** - access to your (go)pass passwords through a dmenu
* **getpassword.sh** - access to (encrypted) passwords for your scripts
* **findpgpkey.py** - obtain OpenPGP key locations from an email and get the public key
* **smount** - mount storages like through a file manager, but in the command line
* **sshmount** - convenience wrapper around sshfs for mounting remote machines via ssh
* **qrclip** - create QR codes from content on the clipboard
* **gpgclip** - do GPG operations on things on the clipboard
* **stodo.sh** - quickly find TODOs in code
dpass
-----
......@@ -182,3 +194,46 @@ don’t care about TODOs of libraries that you use as a dependency.
Requirements: grep, find, xargs
x
---
A script to detect the format of a compressed archive and extract it in the current directory.
You still have to have the unpacking program installed, though. This script just allows you to forget what program you have to apply.
Examples:
$ x stuff.rar
$ x image.iso
$ x that-file.tar.xz
Requires: bash and, optionally, unrar, zip, 7z, xz, gzip, bzip2, etc.
pack
----
This script will compress the given files and folders using either `xz` (or preferably its parallel version `pixz`), `gz` (or preferably its parallel version `pigz`), `bzip2`, or `zip`.
Examples:
$ pack this.file that.folder
$ ls
this.tar.xz
$ pack -m zip that.folder this.file
$ ls
that.zip
$ pack -n archive this.file
$ ls
archive.xz
$ pack -d backup
$ ls
2019-09-23-backup.tar.xz
See `pack -h` for more parameters.
Requirements: `gzip`, `bzip2`, `zip`, optionally (but a really good idea to have) `pixz`, `pigz`.
#!/bin/bash
#
# Pack the given files as well as possible (pixz, pigz) given the
# programs available on the system
#
# Has some additional features like -d/-t to prefix date and/or time to
# the output file name.
#
VERSION="0.1.0"
SELF="$(basename $0)"
XZ=""
[ -x "$(which xz)" ] && XZ="xz"
[ -x "$(which pixz)" ] && XZ="pixz"
GZ=""
[ -x "$(which gzip)" ] && GZ="gzip"
[ -x "$(which pigz)" ] && GZ="pigz"
BZ=""
[ -x "$(which bzip2)" ] && BZ="bzip2"
ZP=""
[ -x "$(which zip)" ] && ZP="zip"
PACKER="$XZ"
[ -z "$PACKER" ] && PACKER="$BZ"
[ -z "$PACKER" ] && PACKER="$GZ"
[ -z "$PACKER" ] && PACKER="$ZP"
TAR="$(which tar)"
DATE="$(date +%Y-%m-%d-)"
TIME="$(date +%H-%M-%S-)"
USE_TIME=""
USE_DATE=""
BASENAME=""
SHOW_HELP=""
USERBASENAME=""
while [ -n "$1" ]
do
if [ "$1" == "--" ]
then
shift
break
fi
if [ "$1" == "-h" ]
then
SHOWHELP="y"
break
fi
if [ "$1" == "-v" ]
then
echo "$SELF: version $VERSION"
echo -n "xz support: "
if [ "$XZ" == 'pixz' ]; then echo "full"; elif [ -z "$XZ" ]; then echo "no"; else echo "yes"; fi
echo -n "gzip support: "
if [ "$GZ" == 'pigz' ]; then echo "full"; elif [ -z "$GZ" ]; then echo "no"; else echo "yes"; fi
echo -n "bzip2 support: "
if [ -z "$BZ" ]; then echo "no"; else echo "yes"; fi
echo -n "zip support: "
if [ -z "$ZP" ]; then echo "no"; else echo "yes"; fi
exit 0
fi
if [ "$1" == "-t" ]
then
shift
USE_TIME="$TIME"
continue
fi
if [ "$1" == "-d" ]
then
shift
USE_DATE="$DATE"
continue
fi
if [ "$1" == "-dt" -o "$1" == "-td" ]
then
shift
USE_TIME="$TIME"
USE_DATE="$DATE"
continue
fi
if [ "$1" == "-f" ]
then
shift
case "$1" in
"xz")
if [ -z "XZ" ]
then
echo "xz is not available."
exit -2
fi
PACKER="$XZ"
;;
"gz")
if [ -z "GZ" ]
then
echo "gz is not available."
exit -2
fi
PACKER="$GZ"
;;
"bz2"|"bzip2")
if [ -z "BZ" ]
then
echo "bzip2 is not available."
exit -2
fi
PACKER="$BZ"
;;
"zip")
if [ -z "ZP" ]
then
echo "zip is not available."
exit -2
fi
PACKER="zip"
;;
*)
echo "Not a valid option."
exit -1
;;
esac
shift
continue
fi
if [ "$1" == "-n" ]
then
shift
USERBASENAME="$1"
shift
continue
fi
break
done
[ -z "$1" ] && SHOWHELP="y"
if [ -n "$SHOWHELP" ]
then
echo "Usage: $SELF [-h] [-v] [-d] [-t] [-n name] [-f format] files..."
echo "-h Show this help and exit"
echo "-v Show version and exit"
echo "-d Prefix current date to output file name"
echo "-t Prefix current time to output file name"
echo "-n name Name of the output file instead of the name of the"
echo " first input file or folder"
echo "-f format Use this compression format instead of xz (xz, zip,"
echo " bzip2, or gzip)"
exit 0
fi
EXT=""
case "$PACKER" in
"zip") EXT=".zip" ;;
"bzip2") EXT=".bz2" ;;
"xz"|"pixz") EXT=".xz" ;;
"gz"|"pigz") EXT=".gz" ;;
*) exit -4 ;;
esac
PACKER="$(which $PACKER)"
if [ -z "$PACKER" ]
then
echo "Compression format not available"
exit -3
fi
BASENAME="$USERBASENAME"
if [ -z "$BASENAME" ]
then
BASENAME="$(basename $1)"
BASENAME="${BASENAME%.*}"
fi
BASENAME="$USE_DATE$USE_TIME$BASENAME"
if [[ "$PACKER" =~ [^bg]zip$ ]]
then
# zip doesn't care if it's one or many
exec $PACKER r "$BASENAME$EXT" $@
elif [ $# -gt 1 -o ! -f "$1" ]
then
exec $TAR -I"$PACKER" -cf "$BASENAME.tar$EXT" $@
else
if [ -z "$USERBASENAME" ]
then
BASENAME="$(basename $1)"
fi
exec "$PACKER" -kc "$1" > "$BASENAME$EXT"
fi
exit -3
#!/bin/bash
KEEP=""
VERBOSE=""
SHOWHELP=""
SELF="$0"
SHIFT=0
for param in "$@"
do
if [ "$param" == "--" ]
then
break
fi
if [ "$param" == "-k" ]
then
KEEP="y"
SHIFT=$((SHIFT+1))
fi
if [ "$param" == "-v" ]
then
VERBOSE="y"
SHIFT=$((SHIFT+1))
fi
if [ "$param" == "-h" ]
then
SHOWHELP="y"
fi
done
if [ "$SHOWHELP" == "y" -o -z "$1" ]
then
echo "Usage: $SELF [-k] [-v] file..."
echo "Tries to guess the file type and extracts the archive"
exit 0
fi
OLDIFS=$IFS
IFS="$(printf '\n\t')"
shift $SHIFT
for FILE in "$@"
do
OPTS=""
case "${FILE%,}" in
*.tar.bz2|*.tbz|*.tbz2|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar|*.cbt)
OPTS="xf"
[ "$VERBOSE" == "y" ] && OPTS+="v"
tar $OPTS "$FILE" ;;
*.zip|*.cbz|*.epub)
[ "$VERBOSE" == "y" ] && OPTS+=" -v"
unzip $OPTS "$FILE" ;;
*.rar|*.cbr)
unrar x "$FILE" ;;
*.xz)
[ "$VERBOSE" == "y" ] && OPTS+=" -v"
[ "$KEEP" == "y" ] && OPTS+=" -k"
unxz $OPTS "$FILE" ;;
*.bz2)
[ "$VERBOSE" == "y" ] && OPTS+=" -v"
[ "$KEEP" == "y" ] && OPTS+=" -k"
bzip2 -d $OPTS "$FILE" ;;
*.gz)
[ "$VERBOSE" == "y" ] && OPTS+=" -v"
[ "$KEEP" == "y" ] && OPTS+=" -k"
gunzip $OPTS "$FILE" ;;
*.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x "$FILE" ;;
*.exe)
cabextract "$FILE" ;;
*.z)
uncompress "$FILE" ;;
*.cpio)
cpio -id < "$FILE" ;;
*.cba|*.ace)
unace x "$FILE" ;;
*.zpaq)
zpaq x "$FILE" ;;
*.arc)
arc e "$FILE" ;;
*.cso)
ciso 0 "$FILE" ./"$FILE".iso ;;
*)
echo "$SELF: '$FILE' - unknown archive"
IFS=$OLDIFS
exit 1
esac
done
IFS=$OLDIFS
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment