rewrite of linkfollow
[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'lla empty the 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
10
11 scriptfile=$XDG_CONFIG_HOME/uzbl/session.sh # this script
12 sessionfile=$XDG_DATA_HOME/uzbl/session # the file in which the "session" (i.e. urls) are stored
13 UZBL="uzbl" # add custom flags and whatever here.
14
15 fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere
16 thisfifo="$4"
17 act="$8"
18 url="$6"
19
20 case $act in
21   "launch" )
22     for url in $(cat $sessionfile); do
23       $UZBL --uri "$url" &
24     done
25     exit 0;;
26   "endinstance" )
27     if [ "$url" != "(null)" ]; then
28       echo "$url" >> $sessionfile;
29     fi
30     echo "exit" > "$thisfifo"
31     ;;
32   "endsession" )
33     echo -n "" > "$sessionfile"
34     for fifo in $fifodir/uzbl_fifo_*; do
35       if [ "$fifo" != "$thisfifo" ]; then
36         echo "spawn $scriptfile endinstance" > "$fifo"
37       fi
38     done
39     echo "spawn $scriptfile endinstance" > "$thisfifo";;
40   * ) echo "session manager: bad action";;
41 esac
42