Update .clang-tidy for Ubuntu 24.04
[geeqie.git] / scripts / keyword_merge.sh
1 #!/bin/bash
2 #
3 # This is a simple script to merge the keyword tree of one Geeqie
4 # configuration file into another.
5 # The keyword trees are simply concatenated. When Geeqie loads
6 # the resulting configuration file, any duplicates are discarded.
7 #
8 # There is no error checking.
9
10 merge_file()
11 {
12 flag=0
13 while read line_merge
14 do
15         if [[ flag -eq 0 ]]
16         then
17                 if [[ $line_merge =~ "<keyword_tree>" ]]
18                 then
19                         flag=1
20                 fi
21         else
22                 if [[ $line_merge =~ "</keyword_tree>" ]]
23                 then
24                         flag=0
25                 else
26                         echo $line_merge >> "$2"
27                 fi
28         fi
29 done < "$1"
30 }
31
32 np=$#
33
34 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
35 if [[ $? -eq 1 ]]
36 then
37         exit
38 fi
39
40
41 if [[ $np -ge 3 ]]
42 then
43         zenity --error --text "Too many parameters"
44         exit
45 elif [[ $np -eq 0 ]]
46 then
47         config_main=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select main configuration file")
48         if [[ $? -eq 1 ]]
49         then
50                 exit
51         fi
52         config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*"-- title="Select configuration file to merge from")
53         if [[ $? -eq 1 ]]
54         then
55                 exit
56         fi
57 elif [[ $np -eq 1 ]]
58 then
59         config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select configuration file to merge from")
60         if [[ $? -eq 1 ]]
61         then
62                 exit
63         fi
64 fi
65
66 tmp_file=$(mktemp)
67
68 while read line_main
69 do
70         if [[ $line_main =~ "</keyword_tree>" ]]
71         then
72                 merge_file  "$config_merge" "$tmp_file"
73         fi
74         echo "$line_main" >> "$tmp_file"
75 done < "$config_main"
76
77 zenity --question --text="Backup configuration file before overwriting?"
78 if [[ $? -eq 0 ]]
79 then
80         cp "$config_main" "$config_main""."$(date +%Y%m%d%H%M%S)
81 fi
82
83 mv "$tmp_file" "$config_main"