From 65434199e5775822255ee639fcc49ccd9a17b58d Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Thu, 28 Jul 2011 18:06:47 -0400 Subject: [PATCH] Added archive listing to extract plugin. --- plugins/extract/_ls-archive | 6 ++++ plugins/extract/extract.plugin.zsh | 53 +++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 plugins/extract/_ls-archive diff --git a/plugins/extract/_ls-archive b/plugins/extract/_ls-archive new file mode 100644 index 00000000..591aeec6 --- /dev/null +++ b/plugins/extract/_ls-archive @@ -0,0 +1,6 @@ +#compdef ls-archive +#autoload + +_arguments \ + '(-v --verbose)'{-v,--remove}'[Verbose archive listing.]' \ + "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|rar|7z)(-.)'" && return 0 diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 02b05eb4..006afad5 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -1,8 +1,8 @@ # ------------------------------------------------------------------------------ # FILE: extract.plugin.zsh # DESCRIPTION: oh-my-zsh plugin file. -# AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com) -# VERSION: 1.0.1 +# AUTHOR: Sorin Ionescu +# VERSION: 1.0.2 # ------------------------------------------------------------------------------ @@ -15,7 +15,7 @@ function extract() { if (( $# == 0 )); then echo "Usage: extract [-option] [file ...]" echo - echo Options: + echo "Options:" echo " -r, --remove Remove archive." echo echo "Report bugs to ." @@ -76,5 +76,50 @@ function extract() { done } -alias x=extract +function ls-archive() { + local verbose + + if (( $# == 0 )); then + echo "Usage: extract [-option] [file ...]" + echo + echo "Options:" + echo " -v, --verbose Verbose archive listing." + echo + echo "Report bugs to ." + fi + + if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then + verbose=0 + shift + fi + + while (( $# > 0 )); do + if [[ ! -f "$1" ]]; then + echo "extract: '$1' is not a valid file" 1>&2 + shift + continue + fi + + case "$1" in + (*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;; + (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ + && tar --xz -t${verbose:+v}f "$1" \ + || xzcat "$1" | tar t${verbose:+v}f - ;; + (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ + && tar --lzma -t${verbose:+v}f "$1" \ + || lzcat "$1" | tar x${verbose:+v}f - ;; + (*.tar) tar t${verbose:+v}f "$1" ;; + (*.zip) unzip -l${verbose:+v} "$1" ;; + (*.rar) unrar ${${verbose:+v}:-l} "$1" ;; + (*.7z) 7za l "$1" ;; + (*) + echo "ls-archive: '$1' cannot be listed" 1>&2 + success=1 + ;; + esac + + shift + done +}