dotfiles2/base/bin/tmux-shim

29 lines
746 B
Plaintext
Raw Normal View History

2022-08-06 05:16:17 +00:00
#!/bin/ksh
# Workaround for some tmux silliness
# TODO: way too hacky
REAL_TMUX=${REAL_TMUX:-/usr/pkg/bin/tmux}
if [ ! -x "$REAL_TMUX" ] ; then
REAL_TMUX="$(which tmux)"
fi
if [ -n "$1" ] ; then
$REAL_TMUX "$@"
exit
fi
myhost="$(hostname)"
SESSION_NAME="${myhost%%.*}"
if $REAL_TMUX ls -F "#{session_name}" | grep -q "^${SESSION_NAME}\$" ; then
# set necessary session variables
for envvar in DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR XDG_SEAT XDG_SESSION_CLASS XDG_SESSION_COOKIE XDG_SESSION_ID XDG_SESSION_TYPE XDG_VTNR ; do
nameref val=$envvar
[ -n "$val" ] && $REAL_TMUX setenv -t $SESSION_NAME $envvar "$val"
done
$REAL_TMUX attach -t $SESSION_NAME
else
$REAL_TMUX new -s $SESSION_NAME
fi