Singleplexing

By chimo on (updated on )

I’ve been using “tmux” as a terminal multiplexer for years (decades? I’m getting old; I lose track). I’m starting an experiment to go without it for local shells (i.e.: I’ll still use tmux on machines I ssh into). Mostly for fun, but also it would be one less thing to rely on.

I think I first started using tmux for remote shells for the following benefits:

  • Being able to detach a session, disconnect from the remote server and being able to re-attach the same session when I reconnect.
  • Have some sort of “window management” without having to SSH into the remote machine multiple times.

For those reasons, I don’t plan on ditching tmux for remote sessions.

I started to use tmux for my local shell probably because I got used to it for my remote shells but maybe also because, unbeknownst to me at the time, I enjoyed the tiling nature of it. I’m fairly sure I was using KDE back then, which by default has KWin as a floating window manager. Coming from Windows at the time, it felt like a natural transition, but looking back at my history with software from that point on, I think gravitated towards the tiling concept over time.

Over the years, I’ve been desktop-environment/window-manager hopping on and off. Fast-forward to today and I’ve settled with Sway, which is a keyboard-driven tiling WM.

If we revisit the tmux benefits above from a “local shell” perspective:

  • I don’t find myself wanting to detach/attach from sessions very often or at all.
  • I have my (tiling) window management covered by Sway and the “SSH” thing doesn’t apply; running a new terminal is just a mod+Enter keypress away.

Maybe I don’t need tmux locally after all…

So for the last couple of days, I’ve been trying to use my terminal (foot) without instinctively typing “tmux” immediately after seeing a prompt. It’s been going well for the most part, except for a couple of snags:

Let’s leave the colour thing for last because it makes me want to flip tables every time I have to deal with it.

GPG pinentry

This might be partially particular to my setup where:

  • I don’t use a login manager. I bootup and get dropped on a tty where I run “sway” to launch the window manager.
  • I use busybox’s “ash” shell.

A long time ago, in order to have GPG’s pinentry to work with “tmux” I added the following to my .profile config:

# ...
export GPG_TTY="$(tty)"
# ...

I didn’t think much of it at the time; things worked, I moved on and forgot about it.

Turns out this works because tmux sources the .profile config when launching (it launches a login shell).

Launching a new “foot” terminal does not launch a login shell. As such, it does not source the .profile config, and the GPG_TTY environment variable does not get updated to the tty associated to the new foot window.

So now the question is: can we get “ash” to source a specific file for non-login shells?

It turns out that yes: ash (and maybe anything POSIX-compliant) will source the file that the “ENV” environment variable points to. Note: I think it needs to be an absolute path to work.

In my case, I opted to add this to my .profile config:

# ...
# Source this file on non-login shells too.
export ENV="$HOME/.ashrc"
# ...

My .ashrc file contains things that should be sourced by non-login shells (such as my aliases):

# This creates a socket in /tmp/ named 'dbus-<random-suffix>'
alias sway="dbus-run-session sway"

# Exit after paste so clipboard content doesn't stick around the process list
alias wl-copy="wl-copy -o" 

# vi -> vim
alias vi="vim"

alias uc="update-containers.sh"
alias uh="doas apk upgrade && rm ~/devel/swaybar/states/updates.state"

# pinentry-tty
export GPG_TTY="$(tty)"

Colours

Terminal colours is a topic that always baffles me whenever I have to deal with it. I should take the time to really understand how it works behind the scenes, but there’s always more interesting things (to me) to learn and fiddle with than colours. So it remains this trial-and-error thing that magically works sometimes and sometimes doesn’t.

Maybe one day I’ll dive into it.

I’m using the “solarized-dark” theme from the foot git repository.

tmux

I’ve been using “solarized-dark” theme from seebi/tmux-colors-solarized.

vim

I originally used “solarized.vim” from altercation/vim-colors-solarized. This works in “tmux” but doesn’t seem to work with foot.

Now I’m using “lifepillar/vim-solarized8”, which works outside of “tmux” and mostly works with “tmux” except the background colour looking odd. Since I’m not planning on using “tmux”, I choose to ignore this issue and pretend everything works.

Conclusion

Despite those minor snags, things have been working well so far. As a bonus, I also kind of like the fact that I don’t need to hit Ctrl+b as a prefix before doing anything window-management related.

I don’t know what I’ll do with all the time I save with all those Ctrl+b I don’t need to type. Maybe travel? Learn a new language? Finally learn terminal colour management? Ha! Probably not… :-)