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