From 9d7f21f504ee55f89621ede3553d0c13d5091bf9 Mon Sep 17 00:00:00 2001 From: Christian Baer Date: Thu, 28 May 2020 23:18:38 +0200 Subject: [PATCH] Added extract function to zsh --- .zsh/functions/extract | 35 +++++++++++++++++++++++++++++++++++ .zsh/lib/functions.zsh | 3 +++ 2 files changed, 38 insertions(+) create mode 100644 .zsh/functions/extract create mode 100644 .zsh/lib/functions.zsh diff --git a/.zsh/functions/extract b/.zsh/functions/extract new file mode 100644 index 0000000..e2c014a --- /dev/null +++ b/.zsh/functions/extract @@ -0,0 +1,35 @@ +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]" + return 1 + else + for n in $@ + do + if [ -f "$n" ] ; then + case "${n%,}" in + *.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar) + tar xvf "$n" ;; + *.lzma) unlzma ./"$n" ;; + *.bz2) bunzip2 ./"$n" ;; + *.rar) unrar x -ad ./"$n" ;; + *.gz) gunzip ./"$n" ;; + *.zip) unzip ./"$n" ;; + *.z) uncompress ./"$n" ;; + *.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar) + 7z x ./"$n" ;; + *.xz) unxz ./"$n" ;; + *.exe) cabextract ./"$n" ;; + *) + echo "extract: '$n' - unknown archive method" + return 1 + ;; + esac + else + echo "'$n' - file does not exist" + return 1 + fi + done +fi +} diff --git a/.zsh/lib/functions.zsh b/.zsh/lib/functions.zsh new file mode 100644 index 0000000..c0dd413 --- /dev/null +++ b/.zsh/lib/functions.zsh @@ -0,0 +1,3 @@ +fpath+=$ZDOTDIR/functions + +autoload extract