make icon setting configurable
[uzbl-mobile] / examples / scripts / session.sh
1 #!/bin/bash
2
3 # Very simple session manager for uzbl.  When called with "endsession" as the
4 # argument, it'll backup $sessionfile, look for fifos in $fifodir and
5 # instruct each of them to store their current url in $sessionfile and
6 # terminate themselves.  Run with "launch" as the argument and an instance of
7 # uzbl will be launched for each stored url.  "endinstance" is used internally
8 # and doesn't need to be called manually at any point.
9 # Add a line like 'bind quit = /path/to/session.sh endsession' to your config
10
11 scriptfile=$0                           # this script
12 sessionfile=$XDG_DATA_HOME/uzbl/session # the file in which the "session" (i.e. urls) are stored
13 configfile=$XDG_DATA_HOME/uzbl/config   # uzbl configuration file
14 UZBL="uzbl -c $configfile"           # add custom flags and whatever here.
15
16 fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere
17 thisfifo="$4"
18 act="$8"
19 url="$6"
20
21 if [ "$act." = "." ]; then
22    act="$1"
23 fi
24
25
26 case $act in
27   "launch" )
28     urls=$(cat $sessionfile)
29     if [ "$urls." = "." ]; then
30       $UZBL
31     else
32       for url in $urls; do
33         $UZBL --uri "$url" &
34       done
35     fi
36     exit 0
37     ;;
38
39   "endinstance" )
40     if [ "$url" != "(null)" ]; then
41       echo "$url" >> $sessionfile;
42     fi
43     echo "exit" > "$thisfifo"
44     ;;
45
46   "endsession" )
47     mv "$sessionfile" "$sessionfile~"
48     for fifo in $fifodir/uzbl_fifo_*; do
49       if [ "$fifo" != "$thisfifo" ]; then
50         echo "spawn $scriptfile endinstance" > "$fifo"
51       fi
52     done
53     echo "spawn $scriptfile endinstance" > "$thisfifo"
54     ;;
55
56   * ) echo "session manager: bad action"
57       echo "Usage: $scriptfile [COMMAND] where commands are:"
58       echo " launch     - Restore a saved session or start a new one"
59       echo " endsession - Quit the running session. Must be called from uzbl"
60       ;;
61 esac
62