From 8045f78b9c6df38dd44a665ed0619ec5dd560991 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 1 Jun 2014 17:53:45 +0200 Subject: Add enforce-configurations script. --- enforce-configurations | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 enforce-configurations 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 -- cgit v1.2.3