From b842fb64377c24a0818318125d8843ceccb1aea5 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Mon, 21 Jan 2019 12:46:36 +0000 Subject: [PATCH] Add utilities plugin with archive `extract` command --- utilities/utilities.plugin.zsh | 24 ++++++++++++++++++++++++ zshrc | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 utilities/utilities.plugin.zsh diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh new file mode 100644 index 0000000..72fb3f2 --- /dev/null +++ b/utilities/utilities.plugin.zsh @@ -0,0 +1,24 @@ +# A collection of various shell utilities. + +# Detect the type and extract an archive file. +extract() { + if [ -f $1 ]; then + case $1 in + *.tar.bz2) tar xvjf $1 ;; + *.tar.gz) tar xvzf $1 ;; + *.tar.xz) gunzip $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xvf $1 ;; + *.tbz2) tar xvjf $1 ;; + *.tgz) tar xvzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7zr x $1 ;; + *) echo "error: unable to extract '$1'" ;; + esac + else + echo "error: file not found '$1'" + fi +} diff --git a/zshrc b/zshrc index 216a016..dca4bbf 100644 --- a/zshrc +++ b/zshrc @@ -31,6 +31,9 @@ source-plugin build # Project sandboxing commands source-plugin sandbox +# Various shell utilities +source-plugin utilities + # Layout tmux window commands [ "$TMUX" != "" ] && source-plugin layout