Update documentation - increase Doxygen usage
[geeqie.git] / scripts / keyword_merge.sh
1 #!/bin/bash
2
3 ## @file
4 ## @brief This is a simple script to merge the keyword tree of one Geeqie
5 ## configuration file into another.  
6 ##
7 ## The keyword trees are simply concatenated. When Geeqie loads
8 ## the resulting configuration file, any duplicates are discarded.
9 ##
10 ## There is no error checking.
11 ##
12
13 merge_file()
14 {
15 flag=0
16 while read -r line_merge
17 do
18         if [[ flag -eq 0 ]]
19         then
20                 if [[ $line_merge =~ "<keyword_tree>" ]]
21                 then
22                         flag=1
23                 fi
24         else
25                 if [[ $line_merge =~ "</keyword_tree>" ]]
26                 then
27                         flag=0
28                 else
29                         echo "$line_merge" >> "$2"
30                 fi
31         fi
32 done < "$1"
33 }
34
35 np=$#
36
37 zenity --info --text="This script will merge the keywords from one Geeqie\nconfiguration file into another.\n\n\The command format is:\nmerge.sh {config. file to merge into} {config. file to merge from}\n\nIf you do not supply parameters, you are prompted.\n\nYou are given the option to backup the main config. file before it is overwritten with the merged data.\n\nEnsure that Geeqie is not running." --title="Geeqie merge keywords" --width=400 --height=200
38 if [[ $? -eq 1 ]]
39 then
40         exit
41 fi
42
43
44 if [[ $np -ge 3 ]]
45 then
46         zenity --error --text "Too many parameters"
47         exit
48 elif [[ $np -eq 0 ]]
49 then
50         config_main=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select main configuration file")
51         if [[ $? -eq 1 ]]
52         then
53                 exit
54         fi
55         config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*"-- title="Select configuration file to merge from")
56         if [[ $? -eq 1 ]]
57         then
58                 exit
59         fi
60 elif [[ $np -eq 1 ]]
61 then
62         config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select configuration file to merge from")
63         if [[ $? -eq 1 ]]
64         then
65                 exit
66         fi
67 fi
68
69 tmp_file=$(mktemp)
70
71 while read -r line_main
72 do
73         if [[ $line_main =~ "</keyword_tree>" ]]
74         then
75                 merge_file "$config_merge" "$tmp_file"
76         fi
77         echo "$line_main" >> "$tmp_file"
78 done < "$config_main"
79
80 zenity --question --text="Backup configuration file before overwriting?"
81 if [[ $? -eq 0 ]]
82 then
83         cp "$config_main" "$config_main.$(date +%Y%m%d%H%M%S)"
84 fi
85
86 mv "$tmp_file" "$config_main"