summarylogtreecommitdiffstats
path: root/geany-openscad.install
diff options
context:
space:
mode:
Diffstat (limited to 'geany-openscad.install')
-rw-r--r--geany-openscad.install35
1 files changed, 35 insertions, 0 deletions
diff --git a/geany-openscad.install b/geany-openscad.install
new file mode 100644
index 000000000000..3df4b448c7fc
--- /dev/null
+++ b/geany-openscad.install
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+declare -r file='/usr/share/geany/filetype_extensions.conf'
+declare -r heading='Extensions'
+declare -r category='Script'
+declare -r key='OpenSCAD'
+declare -r value='*.scad'
+
+post_install() {
+ # insert filetype line if it isn't present, otherwise replace it.
+ if [ -z "`grep "^${key}=" "${file}"`" ] ; then
+ local before="`sed -n "1,/^\[${heading}]/p" "${file}"`"
+ local section="`sed "1,/^\[${heading}]/d;/^\s*$/,\\\$d" $file | \
+ cat - <(echo "${key}=${value};") | \
+ sort -f`"
+ local after="`sed "1,/^\[${heading}]/d;1,/^\s*$/d" "${file}"`"
+
+ echo "${before}" "${section}" $'\n' $'\n' "${after}" > "${file}"
+ else
+ sed -i "s/^\(${key}=.*;\)/\1${value};/" "${file}"
+ fi
+ sed -i "s/^\(${category}=.*\)/\1${key};/" "${file}"
+}
+
+pre_remove() {
+ # remove the *.scad pattern from the OpenSCAD file type.
+ sed -i "s/^\(${key}=.*\)\\${value};/\1/" "${file}"
+
+ # if the OpenSCAD file type has no other patterns,
+ # remove it and its entry in the Script group.
+ if [ -z "`grep "^${key}=.+" "${file}"`" ] ; then
+ sed -i "/^${key}=/d" "${file}"
+ sed -i "s/^\(${category}=.*\)${key};\(.*\)$/\1\2/" "${file}"
+ fi
+}