Skip to content

Instantly share code, notes, and snippets.

@monga
Last active March 14, 2020 10:13
Show Gist options
  • Save monga/ac3f5ca6b0cda43e5aee3320a057b18a to your computer and use it in GitHub Desktop.
Save monga/ac3f5ca6b0cda43e5aee3320a057b18a to your computer and use it in GitHub Desktop.
Script to toggle a graphical window with my main textual terminal windows (managed by tmux)
#!/bin/bash
# Copyright (C) 2020 by Mattia Monga - Distribute freely under GPLv3
# This script is triggered by a shortcut key (I use F12)
# It toggles a graphical window with my main textual terminal windows (managed by tmux)
# If you switch to a textual console you can still peek at them with
# tmux attach-session -t $MYSESSION
# Just in case you want to debug
# exec 3>/tmp/myterminal-$$.log
# BASH_XTRACEFD=3
# set -x
MYSESSION=myterm
# or any other graphical terminal, e.g. gnome-terminal
TERMCMD=kitty
# if you use gnome-terminal, here you need gnome-terminal-server
TERMSESSION=kitty
PID=$(pidof $TERMSESSION)
if [ -n "$PID" ]; then
if tmux has-session -t $MYSESSION ; then
tmux detach-client -s $MYSESSION
kill -9 $PID
fi
else
if tmux has-session -t $MYSESSION ; then
exec $TERMCMD tmux attach-session -t $MYSESSION
else
exec $TERMCMD tmux new-session -A -D -s $MYSESSION
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment