initial checkin
[grml-scripts.git] / usr_bin / fex
1 #!/bin/zsh
2 # Filename:      fex
3 # Purpose:       extract archives via smart frontend
4 # Authors:       grml-team (grml.org), (c) Matthias Kopfermann, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Sam Mai 27 15:12:16 CEST 2006 [mika]
8 ################################################################################
9
10 autoload -U colors && colors
11 emulate zsh
12
13  file=$1
14  qprompt="
15         $fg_bold[red]Really decompress $fg_bold[magenta]${file}$fg[default]? Press y or Y for YES
16         or any other key for NO $fg[default]
17 "
18
19  nothing_to_do="
20         $fg_bold[green]Okay, I will not uncompress the file $fg_bold[magenta]${file}$fg[default]$fg[default] as requested.
21 "
22
23 decision="read -q '?$qprompt'"
24 (( ${+PAGER} )) || local PAGER=less
25
26  if [ -f $file ]
27  then
28          case $file in
29          (*.tar.bz2) 
30                 tar -tvjf $file \
31                        | \
32                      $PAGER && eval $decision && tar -xvjf $file \
33                       || print $nothing_to_do ;;
34          (*.tar.gz)
35                 tar -tvzf $file  | $PAGER && eval $decision \
36                 && tar -xvzf $file \
37                 || print $nothing_to_do ;;
38          (*.bz2)
39                 bzip2 -tv $file  | $PAGER && eval $decision \
40                 && bzip2 -vd $file || print $nothing_to_do ;;
41          (*.gz)
42                 gzip -tv  $file | $PAGER && eval $decision \
43                 && gzip -d $file || print $nothing_to_do ;;
44          (*.tar)
45                 tar -tvf $file | $PAGER && eval $decision \
46                 && tar xvf $file || print $nothing_to_do ;;
47          (*.tgz)
48                 tar -tvzf $file | $PAGER&& eval $decision \
49                 && tar xzvf $file || print $nothing_to_do ;;
50          (*.zip)
51                 unzip -tv $file | $PAGER&& eval $decision \
52                 && unzip $file || print $nothing_to_do ;;
53          (*.Z)
54                 uncompress -tv $file | $PAGER && eval $decision \
55                 && uncompress -v $file || print $nothing_to_do ;;
56          (*.rar)
57                 unrar t $file | $PAGER && eval $decision \
58                 && unrar x $file || print $nothing_to_do ;; 
59          (*.lzo)
60                 lzop -t $file | $PAGER && eval $decision \
61                 && lzop -x $file || print $nothing_to_do ;;
62          (*)
63                 echo 'Error. Not the expected arguments!'
64                 echo "Usage: $0 file" ; exit 1 ;;
65          esac
66  else
67          echo "'$file' is not a valid file"
68  fi
69
70 ## END OF FILE #################################################################