fix missing bold for your account item
[brisk.git] / bin / 3fire.sh
1 #!/bin/bash
2 # set -x
3 declare -a coor pids
4 coor[0]="0,0,0,560,650"
5 coor[1]="0,443,108,560,650"
6 coor[2]="0,878,197,560,650"
7
8
9 # TODO: pids2wids function IN: pids OUT: associated windows ids
10
11 ffox () {
12     if [ "$1" = "-v" ]; then
13         ps ax | egrep '[0-9] /usr/lib/firefox/firefox -no-remote -P (one|two|three) ' | grep -v grep | sed 's/^ *//g;s/ .*-P//g;s/ http.*//g'
14     else
15         ps ax | egrep '[0-9] /usr/lib/firefox/firefox -no-remote -P (one|two|three) ' | grep -v grep | sed 's/^ *//g;s/ .*//g'
16     fi
17 }
18
19 rearrange_windows () {
20     ct=0
21     while true; do
22         sleep 1
23         wids="$(wmctrl -l -p | sed 's/ \+/|/g' | cut -d '|' -f 1,3 | egrep "\|(${pids[0]}|${pids[1]}|${pids[2]})$")"
24         l="$(echo "$wids" | wc -l)"
25         if [ $l -eq 3 ]; then
26             for i in $(seq 0 2); do
27                 wid="$(echo "$wids" | grep "|${pids[$i]}\$" | cut -d '|' -f 1)"
28                 wmctrl -i -r $wid -e ${coor[$i]}
29                 echo wmctrl out: $?
30             done
31             break
32         fi
33         ct=$((ct + 1))
34         if [ $ct -gt 10 ]; then
35             break
36         fi
37     done
38 }
39
40 #
41 #  MAIN
42 #
43 HOMEPAGE="http://dodo.birds.van/brisk/index.php"
44 if [ "$1" = "help" -o "$1" = "-h" -o "$1" = "--help" ]; then
45     echo "$0       - run firefoxes"
46     echo "$0 list [-v] - list firefoxes"
47     echo "$0 <stop|cont|term|kill> - send signal to firefoxes"
48     echo "$0 help  - this help"
49 elif [ "$1" = "list" ]; then
50     ffox $2
51 elif [ "$1" = "stop" -o "$1" = "cont" -o "$1" = "term" -o "$1" = "kill" ]; then
52     case "$1" in
53         stop) sig=-STOP ;;
54         cont) sig=-CONT ;;
55         term) sig=-TERM ;;
56         kill) sig=-KILL ;;
57     esac
58     
59     kill $sig $(ffox)
60 elif [ "$1" = "rearrange" ]; then
61     list="$($0 list -v)"
62     declare -a pids
63     ct=0
64     for i in one two three; do
65         pids[$ct]="$(echo "$list" | grep -- " $i$" | sed 's/ .*//g')"
66         ct=$((ct + 1))
67     done
68     rearrange_windows
69 elif [ $# -eq 0 ]; then
70     ct=0
71     for i in one two three; do
72         firefox -no-remote -P $i "$HOMEPAGE?whoami=$i" &
73         pd="$!"
74         echo "$i: $pd"
75         pids[$ct]="$pd"
76         ct=$((ct + 1))
77     done
78
79     rearrange_windows
80 fi