forked from dracula/libreoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-FreeBSD-dracula-application-colors.sh
executable file
·44 lines (38 loc) · 1.42 KB
/
add-FreeBSD-dracula-application-colors.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# Check OS platform
if [ "$(uname)" = "FreeBSD" ]; then
fname=$(echo "$(cd ${XDG_CONFIG_HOME:-$HOME/.config}/libreoffice/*/user/ && pwd)"/registrymodifications.xcu)
else
echo "Unsupported kernel. Aborting ..."
exit 1
fi
# Create backup of LibreOffice registry before modifications
cp -i "$fname" registrymodifications.xcu.bak
# Check settings file
if ! [ -f "$fname" ]; then
echo "Settings file doesn't exist in expected location. Aborting ..."
exit 1
elif ! tail -n 1 "$fname" | grep -E -q '^</oor:items>$'; then
echo "Settings file doesn't match expected format. Aborting ..."
exit 1
fi
# Check if color scheme it present already
existing_theme="$(grep -n \
'<item oor:path="/org.openoffice.Office.UI/ColorScheme/ColorSchemes"><node oor:name="Dracula"' \
$fname)"
exit_code=$?
theme_line="$(echo "$existing_theme" | sed 's|:.*||')"
if [ $exit_code -eq 0 ]; then
echo "Dracula theme appears to already be installed. Replacing it ..."
# Replace existing line with
settings_start="$(head -n $theme_line $fname | sed \$d)"
settings_end="$(tail -n +$theme_line $fname | tail -n +2)"
new_settings="$(echo "$settings_start" \
&& cat dracula.xcu \
&& echo "$settings_end")"
else
# Insert theme between last two lines if not present
new_settings="$(sed \$d $fname && cat dracula.xcu && tail -n 1 $fname)"
fi
# Write new settings to settings file
echo "$new_settings" > "$fname"