From 3cc0bf1f69b9b03e324f18f74e23fbbfb7ef9605 Mon Sep 17 00:00:00 2001 From: jon Date: Sat, 25 Jan 2020 17:09:52 -0600 Subject: [PATCH] Added ex() function to .bashrc - used to ex(tract) any filetype --- bash/.bashrc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bash/.bashrc b/bash/.bashrc index 72ee9ab..a9f1c66 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -73,3 +73,43 @@ unset command_not_found_handle if [ -f /usr/share/fzf/shell/key-bindings.bash ]; then source /usr/share/fzf/shell/key-bindings.bash fi + + +ex() { + local c e i + + (($#)) || return + + for i; do + c='' + e=1 + + if [ $# -eq 0 ]; then + echo "No file specified" + exit + fi + + if [[ ! -r $i ]]; then + echo "$0: file is unreadable: \`$i'" >&2 + continue + fi + + case $i in + *.tar) c=(tar xf);; + *.7z) c=(7z x);; + *.Z) c=(uncompress);; + *.bz2) c=(bunzip2);; + *.exe) c=(cabextract);; + *.gz) c=(gunzip);; + *.rar) c=(unrar x);; + *.xz) c=(unxz);; + *.zip) c=(unzip);; + *) echo "$0: unrecognized file extension: \`$i'" >&2 + continue;; + esac + + command "${c[@]}" "$i" + ((e = e || $?)) + done + return "$e" +}