From 0acec18969e0c3540b09a49802c8f75b3d9b96f4 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 6 Feb 2009 17:16:19 +0100 Subject: [PATCH] Autoload functions in ~/.zsh/functions. Also add extract script to ~/.zsh/functions which extracts many different archive formats. Thanks to Eric P. Mangold for this great script. --- zsh/functions/extract | 39 +++++++++++++++++++++++++++++++++++++++ zsh/rc | 7 +++++++ 2 files changed, 46 insertions(+) create mode 100644 zsh/functions/extract diff --git a/zsh/functions/extract b/zsh/functions/extract new file mode 100644 index 0000000..2fa5304 --- /dev/null +++ b/zsh/functions/extract @@ -0,0 +1,39 @@ +# Author: Copyright © 2005 Eric P. Mangold - teratorn (-at-) gmail (-dot) com +# License: MIT. http://www.opensource.org/licenses/mit-license.html +# http://zshwiki.org/home/examples/functions + +local old_dirs current_dirs lower +lower=${(L)1} +old_dirs=( *(N/) ) +if [[ $lower == *.tar.gz || $lower == *.tgz ]]; then + tar zxfv $1 +elif [[ $lower == *.gz ]]; then + gunzip $1 +elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]; then + bunzip2 -c $1 | tar xfv - +elif [[ $lower == *.bz2 ]]; then + bunzip2 $1 +elif [[ $lower == *.zip ]]; then + unzip $1 +elif [[ $lower == *.rar ]]; then + unrar e $1 +elif [[ $lower == *.tar ]]; then + tar xfv $1 +elif [[ $lower == *.lha ]]; then + lha e $1 +else + print "Unknown archive type: $1" + return 1 +fi +# Change in to the newly created directory, and +# list the directory contents, if there is one. +current_dirs=( *(N/) ) +for i in {1..${#current_dirs}}; do + if [[ $current_dirs[$i] != $old_dirs[$i] ]]; then + cd $current_dirs[$i] + ls + break + fi +done + +#compdef '_files -g "*.gz *.tgz *.bz2 *.tbz *.zip *.rar *.tar *.lha"' extract_archive diff --git a/zsh/rc b/zsh/rc index 3647dd4..b8ad05f 100644 --- a/zsh/rc +++ b/zsh/rc @@ -261,6 +261,13 @@ function ll() { la -l $* } +# Set correct fpath to allow loading my functions (including completion +# functions). +fpath=(~/.zsh/functions $fpath) +# Autoload my functions (except completion functions). Thanks to caphuso from +# the Zsh example files for this idea. +autoload ${fpath[1]}/^_*(:t) + # If ^C is pressed while typing a command, add it to the history so it can be # easily retrieved later and then abort like ^C normally does. This is useful # when I want to abort an command to do something in between and then finish -- 2.45.2