#!/bin/zsh
session=${TMUX%%,*}.session/${TMUX_PANE#%}
if ! [[ -d $session ]]; then
	mkdir -p $session
	echo 'w3m' >$session/app
	echo file://${HOME}/.w3m/bookmark.html >$session/url
fi

while true; do
	app=$(<$session/app)
	opts=()
	case $app in
		(exit) rm -r $session; exit;;
		(w3m) opts=( -title=xterm -config ${0:h}/w3m.config );;
	esac
	$app $opts $(<$session/url)
	ret=$?
	if (($ret)); then
		print "exit code:" $ret
		sleep 1
	fi
done