Fix #299: File Compression and Archiving
[geeqie.git] / plugins / open-archive / geeqie-open-archive
1 #!/bin/bash
2
3 # Extract the contents of an archive file to a
4 # temporary folder under /tmp.
5 #
6 # Open a new Geeqie window pointing to that folder.
7
8 full_path=$(realpath "$1")
9 filename=$(basename -- "$1")
10 extension="${filename#*.}"
11
12 case $extension in
13
14         zip)
15                 if [ $(which unzip > /dev/null; echo $? ) = 0 ]
16                 then
17                         rm --recursive --force "/tmp/geeqie-archive/$full_path"
18                         mkdir --parents "/tmp/geeqie-archive/$full_path"
19                         unzip "$full_path" -d "/tmp/geeqie-archive/$full_path" > /dev/null
20                         geeqie --remote --new-window "/tmp/geeqie-archive/$full_path"
21                 else
22                         zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility unzip is not installed"  
23                 fi
24         ;;
25
26         tar.gz)
27                 if [ $(which tar > /dev/null; echo $? ) = 0 ]
28                 then
29                         rm --recursive --force "/tmp/geeqie-archive/$full_path"
30                         mkdir --parents "/tmp/geeqie-archive/$full_path"
31                         tar --extract --gunzip --directory "/tmp/geeqie-archive/$full_path" --file="$full_path"  > /dev/null
32                         geeqie --remote --new-window "/tmp/geeqie-archive/$full_path"
33                 else
34                         zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility tar is not installed"  
35                 fi
36         ;;
37
38         cbr | rar)
39                 if [ $(which unrar > /dev/null; echo $? ) = 0 ]
40                 then
41                         rm --recursive --force rf "/tmp/geeqie-archive/$full_path"
42                         mkdir --parents "/tmp/geeqie-archive/$full_path"
43                         unrar "$full_path" "/tmp/geeqie-archive/$full_path" > /dev/null
44                         geeqie --remote --new-window "/tmp/geeqie-archive/$full_path"
45                 else
46                         zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility unrar is not installed"  
47                 fi
48    ;;
49
50         *)
51                 zenity --title="Geeqie Open Archive" --info --width=300 --text="This is not a known archive file type"  
52     ;;
53 esac
54