summaryrefslogtreecommitdiff
path: root/enforce-configurations
blob: d1c40515d0480cefbf0cb6a43eb799a87ea6b701 (plain)
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
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