forked from dracula/libreoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-dracula-application-colors.sh
executable file
·52 lines (46 loc) · 1.75 KB
/
add-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
45
46
47
48
49
50
51
52
#!/bin/sh
# Check OS platform
if [ "$(uname)" = "Linux" ]; then
fname="${XDG_CONFIG_HOME:-$HOME/.config}"/libreoffice/*/user/registrymodifications.xcu
fname="$(realpath $fname)" # expand
elif [ "$(uname -o)" = "Msys" ]; then
fname="$HOME/AppData/Roaming/LibreOffice"/*/user/registrymodifications.xcu
fname="$(realpath $fname)"
elif [ "$(uname)" = "Darwin" ]; then
cd "$HOME/Library/Application Support/LibreOffice"/*/user # no realpath on macos
fname="$(pwd)/registrymodifications.xcu"
cd - >/dev/null
else
echo "Unsupported operating system. 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 -n1 "$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-1)) "$fname")"
settings_end="$(tail -n +$((theme_line+1)) "$fname")"
new_settings="$(echo "$settings_start" \
&& cat dracula.xcu \
&& echo "$settings_end")"
else
# Insert theme between last two lines if not present
new_settings="$(head -n $(($(<"$fname" wc -l)-1)) "$fname" && cat dracula.xcu && tail -n1 "$fname")"
fi
# Write new settings to settings file
echo "$new_settings" > "$fname"