summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-09-24 12:21:56 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-09-24 12:21:56 +0530
commit86f99da8d08e1f2e290d8ebfd5adb016faff7bac (patch)
tree8f121a2aaa187d8266e20df23ad36262ab051866 /ext
downloadbin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.tar.gz
bin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.tar.bz2
bin-86f99da8d08e1f2e290d8ebfd5adb016faff7bac.zip
script's
Diffstat (limited to 'ext')
-rwxr-xr-xext45
1 files changed, 45 insertions, 0 deletions
diff --git a/ext b/ext
new file mode 100755
index 0000000..6950ff6
--- /dev/null
+++ b/ext
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# A general, all-purpose extraction script. Not all extraction programs here
+# are installed by LARBS automatically.
+#
+# Default behavior: Extract archive into new directory
+# Behavior with `-c` option: Extract contents into current directory
+
+while getopts "hc" o; do case "${o}" in
+ c) extracthere="True" ;;
+ *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;;
+esac done
+
+if [ -z "$extracthere" ]; then
+ archive="$(readlink -f "$*")" &&
+ directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" &&
+ mkdir -p "$directory" &&
+ cd "$directory" || exit 1
+else
+ archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)"
+fi
+
+[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1
+
+if [ -f "$archive" ] ; then
+ case "$archive" in
+ *.tar.bz2|*.tbz2) bsdtar -xf "$archive" ;;
+ *.tar.xz) bsdtar -xf "$archive" ;;
+ *.tar.gz|*.tgz) bsdtar -xf "$archive" ;;
+ *.tar.zst) bsdtar -xf "$archive" ;;
+ *.tar) bsdtar -xf "$archive" ;;
+ *.lzma) unlzma "$archive" ;;
+ *.bz2) bunzip2 "$archive" ;;
+ *.rar) unrar x -ad "$archive" ;;
+ *.gz) gunzip "$archive" ;;
+ *.zip) unzip "$archive" ;;
+ *.Z) uncompress "$archive" ;;
+ *.7z) 7z x "$archive" ;;
+ *.xz) unxz "$archive" ;;
+ *.exe) cabextract "$archive" ;;
+ *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
+ esac
+else
+ printf "File \"%s\" not found.\\n" "$archive"
+fi