aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts/session.sh
diff options
context:
space:
mode:
Diffstat (limited to 'examples/data/scripts/session.sh')
-rwxr-xr-xexamples/data/scripts/session.sh103
1 files changed, 55 insertions, 48 deletions
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index 1059b5e..046ad64 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -8,55 +8,62 @@
# and doesn't need to be called manually at any point.
# Add a line like 'bind quit = /path/to/session.sh endsession' to your config
-[ -d ${XDG_DATA_HOME:-$HOME/.local/share}/uzbl ] || exit 1
-scriptfile=$0 # this script
-sessionfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/browser-session # the file in which the "session" (i.e. urls) are stored
-configfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/config # uzbl configuration file
-UZBL="uzbl-browser -c $configfile" # add custom flags and whatever here.
-
-fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere
-thisfifo="$4"
-act="$8"
-url="$6"
-
-if [ "$act." = "." ]; then
- act="$1"
-fi
+. $UZBL_UTIL_DIR/uzbl-args.sh
+. $UZBL_UTIL_DIR/uzbl-dir.sh
+
+[ -d $UZBL_DATA_DIR ] || exit 1
+
+scriptfile=$0 # this script
+UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here.
+
+act="$1"
+# Test if we were run alone or from uzbl
+if [ -z "$UZBL_SOCKET" ]; then
+ # Take the old config
+ act="$UZBL_CONFIG"
+fi
case $act in
- "launch" )
- urls=`cat $sessionfile`
- if [ "$urls." = "." ]; then
- $UZBL
- else
- for url in $urls; do
- $UZBL --uri "$url" &
- done
- fi
- exit 0
- ;;
-
- "endinstance" )
- if [ "$url" != "(null)" ]; then
- echo "$url" >> $sessionfile;
- fi
- echo "exit" > "$thisfifo"
- ;;
-
- "endsession" )
- mv "$sessionfile" "$sessionfile~"
- for fifo in $fifodir/uzbl_fifo_*; do
- if [ "$fifo" != "$thisfifo" ]; then
- echo "spawn $scriptfile endinstance" > "$fifo"
- fi
- done
- echo "spawn $scriptfile endinstance" > "$thisfifo"
- ;;
-
- * ) echo "session manager: bad action"
- echo "Usage: $scriptfile [COMMAND] where commands are:"
- echo " launch - Restore a saved session or start a new one"
- echo " endsession - Quit the running session. Must be called from uzbl"
- ;;
+ "launch" )
+ urls=$(cat $UZBL_SESSION_FILE)
+ if [ -z "$urls" ]; then
+ $UZBL
+ else
+ for url in $urls; do
+ $UZBL --uri "$url" &
+ disown
+ done
+ fi
+ exit 0
+ ;;
+
+ "endinstance" )
+ if [ -z "$UZBL_SOCKET" ]; then
+ echo "session manager: endinstance must be called from uzbl"
+ exit 1
+ fi
+ if [ ! "$UZBL_URL" = "(null)" ]; then
+ echo "$UZBL_URL" >> $UZBL_SESSION_FILE
+ fi
+ echo "exit" | socat - unix-connect:$UZBL_SOCKET
+ ;;
+
+ "endsession" )
+ mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~"
+ for sock in $UZBL_SOCKET_DIR/uzbl_fifo_*; do
+ if [ "$sock" != "$UZBL_SOCKET" ]; then
+ echo "spawn $scriptfile endinstance" | socat - unix-connect:$socket
+ fi
+ done
+ echo "spawn $scriptfile endinstance" | socat - unix-connect:$UZBL_SOCKET
+ ;;
+
+ * )
+ echo "session manager: bad action"
+ echo "Usage: $scriptfile [COMMAND] where commands are:"
+ echo " launch - Restore a saved session or start a new one"
+ echo " endinstance - Quit the current instance. Must be called from uzbl"
+ echo " endsession - Quit the running session."
+ ;;
esac