My favorite shell scripts (part 1)
This is yet another “Linux Desktop is fun” post. Without further ado, let’s cut to the chase.
This will hopefully turn into a series of short shell scripts I find somewhat amusing in my everyday computer life.
You can look them up here.
Part 1: Activate single terminal instance, with single tmux session
This is the behaviour I wanted to emulate in KDE Plasma after leaving the iterm2 world.
My muscle memory likes
The combination should launch either a new instance or the already active one.
The default key shortcuts set up allowed me to spawn a new program instance every time the keystroke was made.
Anyway, here we go:
TERMINAL is defined upfront. As far as the Desktop Environment is concerned,
it doesn’t matter. We obtain X11 Window ID by using
xdotool searching for the
$TERMINAL instance, sorting the results, so we can get somewhat
predictable ordering (a weak assumption that we’ll always hit the oldest
head -n1 just takes the first one.
xdotoolis capable of much more, make sure to check
Having the non-existing Window ID, we just launch
$TERMINAL making it execute
tmux -u on
-u flag is helpful for enforcing unicode support within the
-u When starting, tmux looks for the LC_ALL, LC_CTYPE and LANG environment variables: if the first found contains ‘UTF-8’, then the terminal is assumed to support UTF-8. This is not always correct: the -u flag explicitly informs tmux that UTF-8 is sup‐ ported.
Otherwise, we have an existing Window ID. We use that to activate an existing
X11 window, bringing up an already opened Terminal, hoping for the
session to be there. Worst case, we just launch
tmux manually and pick a
session we wanted to get back to.
That should be straight-forward to integrate with
Plasma Settings at this point, just don’t forget
to make the
actterm script executable first.