summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2014-06-01 17:53:45 +0200
committercos <cos>2014-06-01 17:53:45 +0200
commit8045f78b9c6df38dd44a665ed0619ec5dd560991 (patch)
treeedec63df7253c8fcdf730840fdafe5e5bc0c5cd6
parent0f2bb5ae1369d52dc7071e01b979485d687effae (diff)
downloadgo-webbrowser-launcher-8045f78b9c6df38dd44a665ed0619ec5dd560991.zip
Add enforce-configurations script.
-rwxr-xr-xenforce-configurations53
1 files changed, 53 insertions, 0 deletions
diff --git a/enforce-configurations b/enforce-configurations
new file mode 100755
index 0000000..d1c4051
--- /dev/null
+++ b/enforce-configurations
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+set -e
+
+VERBOSE=0
+
+is_profile()
+{
+ local directory=$1
+
+ [ -f "$directory/bookmarks" ]
+}
+
+echo_debug()
+{
+ if [ $VERBOSE != 0 ]
+ then
+ echo $@
+ fi
+}
+
+for dir in ${XDG_CONFIG_HOME:-~/.config/dwb}/*
+do
+ profile=`basename "$dir"`
+ if is_profile $dir
+ then
+ echo_debug "Enforcing configuration for dwb profile $profile."
+ existing_config=`awk < ${XDG_CONFIG_HOME:-~/.config/dwb/}/settings \
+ "/\[$profile\]/ { print ; while (/./ && getline) { print } }"`
+ echo_debug " "existing_config: `echo "$existing_config"|wc -l` \
+ `echo "$existing_config"|head -1`
+
+ dwb_execute=""
+ for config_option in `cat ~/.go/config|cut -d= -f1`
+ do
+ config_value=`cat ~/.go/config|sed --silent "s/$config_option=//p"`
+ if (echo "$existing_config"|
+ grep -q "`echo $config_option=$config_value`")
+ then
+ :
+ else
+ dwb_execute="${dwb_execute:+$dwb_execute;; }set $config_option $config_value"
+ fi
+ done
+ if ps xaf|grep dwb|grep --quiet =$profile
+ then
+ echo "A browser using the $profile profile seems to be running. Skipping it."
+ else
+ echo_debug " config command: $dwb_execute"
+ [ -z "$dwb_execute" ] || dwb --profile="$profile" --execute="$dwb_execute;; quit" &
+ fi
+ fi
+done