From 7beeaca593cf9b892ca895787c6485efd289ce36 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 28 Jan 2021 01:52:08 +0000 Subject: [PATCH] Update .zshrc --- .zshrc | 66 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/.zshrc b/.zshrc index 200cba7..6798573 100644 --- a/.zshrc +++ b/.zshrc @@ -41,33 +41,49 @@ case ${TERM} in ;; esac -### ARCHIVE EXTRACTION -# usage: ex -ex () -{ - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xjf $1 ;; - *.tar.gz) tar xzf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xf $1 ;; - *.tbz2) tar xjf $1 ;; - *.tgz) tar xzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1;; - *.7z) 7z x $1 ;; - *.deb) ar x $1 ;; - *.tar.xz) tar xf $1 ;; - *.tar.zst) unzstd $1 ;; - *) echo "'$1' cannot be extracted via ex()" ;; - esac - else - echo "'$1' is not a valid file" - fi +### Function extract for common file formats ### +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") + +function extract { + if [ -z "$1" ]; then + # display usage if no parameters given + echo "Usage: extract ." + echo " extract [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 xvf "$n" ;; + *.lzma) unlzma ./"$n" ;; + *.bz2) bunzip2 ./"$n" ;; + *.cbr|*.rar) unrar x -ad ./"$n" ;; + *.gz) gunzip ./"$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 + ### OH MY ZSH ### # Path to your oh-my-zsh installation.