feat(user/bkunzip):Add custom unzip bash function
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 20 Feb 2024 21:38:03 +0000 (21:38 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 20 Feb 2024 21:38:03 +0000 (21:38 +0000)
user/bkunzip [new file with mode: 0644]

diff --git a/user/bkunzip b/user/bkunzip
new file mode 100644 (file)
index 0000000..3e0e8e7
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+function bkunzip() {
+    # Desc: Uncompresses zip file.
+    # Depends: unzip
+    # Version: 0.0.1
+    
+    for fin in "$@"; do
+        if [[ -f "$fin" && "$fin" =~ \.zip$ ]]; then
+            # Remove the file extension to create a directory name
+            dir="${fin%.*}";
+            # Create the directory if it doesn't exist
+            mkdir -p "$dir" || \
+                { echo "ERROR:Could not mkdir:$dir"; return 1; };
+            # Extract the zip file into the directory
+            unzip "$fin" -x / -d "$dir"  || \
+                { echo "ERROR:Could not unzip:$fin"; return 1; };
+        else
+            echo "ERROR:Not a valid zip file:$fin" 1>&2; return 1;
+        fi;
+    done;
+}; # wrapper for unzip
+
+printf "WARNING:$0:This is a bash function definition."