From f0a435df3339c2f0ddca97f83f58073c4988f15d Mon Sep 17 00:00:00 2001
From: Paul Buetow
-
Technical references
@@ -104,51 +104,51 @@
Self-development and soft-skills books
In random order:
-
Here are notes of mine for some of the books
@@ -157,31 +157,31 @@
Some of these were in-person with exams; others were online learning lectures only. In random order:
-
Technical guides
These are not whole books, but guides (smaller or larger) which I found very useful. in random order:
-
Podcasts
@@ -190,58 +190,58 @@
In random order:
-
Podcasts I liked
I liked them but am not listening to them anymore. The podcasts have either "finished" (no more episodes) or I stopped listening to them due to time constraints or a shift in my interests.
-
Newsletters I like
This is a mix of tech and non-tech newsletters I am subscribed to. In random order:
-
Magazines I like(d)
This is a mix of tech I like(d). I may not be a current subscriber, but now and then, I buy an issue. In random order:
-
Formal education
diff --git a/gemfeed/2024-06-23-terminal-multiplexing-with-tmux.html b/gemfeed/2024-06-23-terminal-multiplexing-with-tmux.html
index e39ce96c..cfbc6a53 100644
--- a/gemfeed/2024-06-23-terminal-multiplexing-with-tmux.html
+++ b/gemfeed/2024-06-23-terminal-multiplexing-with-tmux.html
@@ -2,7 +2,7 @@
-Terminal multiplexing with tmux
+Terminal multiplexing with tmux - Z-Shell edition
-Published at 2024-06-23T22:41:59+03:00
+Published at 2024-06-23T22:41:59+03:00; Last updated 2025-05-02
+
+This is the Z-Shell version. There is also a Fish version:
+
+./2025-05-02-terminal-multiplexing-with-tmux-fish-edition.html
Tmux (Terminal Multiplexer) is a powerful, terminal-based tool that manages multiple terminal sessions within a single window. Here are some of its primary features and functionalities:
@@ -40,7 +44,7 @@ jgs `-=========-`()
Table of Contents
-
Terminal multiplexing with tmux - Fish edition
+
+Published at 2025-05-02T00:09:23+03:00
+
+This is the Fish shell edition of the same post of mine from last year:
+
+./2024-06-23-terminal-multiplexing-with-tmux.html
+
+Tmux (Terminal Multiplexer) is a powerful, terminal-based tool that manages multiple terminal sessions within a single window. Here are some of its primary features and functionalities:
+
+
+
+https://github.com/tmux/tmux/wiki
+
+
+ _______
+ |.-----.|
+ || Tmux||
+ ||_.-._||
+ `--)-(--`
+ __[=== o]___
+ |:::::::::::|\
+jgs `-=========-`()
+ mod. by Paul B.
+
+
+Table of Contents
+
+
+
+Before continuing...
+
+Before continuing to read this post, I encourage you to get familiar with Tmux first (unless you already know the basics). You can go through the official getting started guide:
+
+https://github.com/tmux/tmux/wiki/Getting-Started
+
+I can also recommend this book (this is the book I got started with with Tmux):
+
+https://pragprog.com/titles/bhtmux2/tmux-2/
+
+Over the years, I have built a couple of shell helper functions to optimize my workflows. Tmux is extensively integrated into my daily workflows (personal and work). I had colleagues asking me about my Tmux config and helper scripts for Tmux several times. It would be neat to blog about it so that everyone interested in it can make a copy of my configuration and scripts.
+
+The configuration and scripts in this blog post are only the non-work-specific parts. There are more helper scripts, which I only use for work (and aren't really useful outside of work due to the way servers and clusters are structured there).
+
+Tmux is highly configurable, and I think I am only scratching the surface of what is possible with it. Nevertheless, it may still be useful for you. I also love that Tmux is part of the OpenBSD base system!
+
+Shell aliases
+
+Since last week, I switched to the Fish shell. As a result, I also had to convert all my tmux helper scripts (mentioned in this blog post) to Fish.
+
+https://fishshell.com
+
+For the most common Tmux commands I use, I have created the following shell aliases:
+
+
+alias tn 'tmux::new'
+alias ta 'tmux::attach'
+alias tx 'tmux::remote'
+alias ts 'tmux::search'
+alias tssh 'tmux::cluster_ssh'
+alias tm tmux
+alias tl 'tmux list-sessions'
+alias foo 'tmux::new foo'
+alias bar 'tmux::new bar'
+alias baz 'tmux::new baz'
+
+
+Note all tmux::...; those are custom shell functions doing certain things, and they aren't part of the Tmux distribution. But let's run through every aliases one by one.
+
+The first two are pretty straightforward. tm is simply a shorthand for tmux, so I have to type less, and tl lists all Tmux sessions that are currently open. No magic here.
+
+The tn alias - Creating a new session
+
+The tn alias is referencing this function:
+
+
+# Create new session and if alread exists attach to it
+function tmux::new
+ set -l session $argv[1]
+ _tmux::cleanup_default
+ if test -z "$session"
+ tmux::new (string join "" T (date +%s))
+ else
+ tmux new-session -d -s $session
+ tmux -2 attach-session -t $session || tmux -2 switch-client -t $session
+ end
+end
+
+
+There is a lot going on here. Let's have a detailed look at what it is doing.
+
+First, a Tmux session name can be passed to the function as a first argument. That session name is only optional. Without it, Tmux will select a session named (string join "" T (date +%s)) as a default. Which is T followed by the UNIX epoch, e.g. T1717133796.
+
+Cleaning up default sessions automatically
+
+Note also the call to _tmux::cleanup_default; it would clean up all already opened default sessions if they aren't attached. Those sessions were only temporary, and I had too many flying around after a while. So, I decided to auto-delete the sessions if they weren't attached. If I want to keep sessions around, I will rename them with the Tmux command prefix-key $. This is the cleanup function:
+
+
+function _tmux::cleanup_default
+ tmux list-sessions | string match -r '^T.*: ' | string match -v -r attached | string split ':' | while read -l s
+ echo "Killing $s"
+ tmux kill-session -t "$s"
+ end
+end
+
+
+The cleanup function kills all open Tmux sessions that haven't been renamed properly yet—but only if they aren't attached (e.g., don't run in the foreground in any terminal). Cleaning them up automatically keeps my Tmux sessions as neat and tidy as possible.
+
+Renaming sessions
+
+Whenever I am in a temporary session (named T....), I may decide that I want to keep this session around. I have to rename the session to prevent the cleanup function from doing its thing. That's, as mentioned already, easily accomplished with the standard prefix-key $ Tmux command.
+
+The ta alias - Attaching to a session
+
+This alias refers to the following function, which tries to attach to an already-running Tmux session.
+
+
+function tmux::attach
+ set -l session $argv[1]
+ if test -z "$session"
+ tmux attach-session || tmux::new
+ else
+ tmux attach-session -t $session || tmux::new $session
+ end
+end
+
+
+If no session is specified (as the argument of the function), it will try to attach to the first open session. If no Tmux server is running, it will create a new one with tmux::new. Otherwise, with a session name given as the argument, it will attach to it. If unsuccessful (e.g., the session doesn't exist), it will be created and attached to.
+
+The tr alias - For a nested remote session
+
+This SSHs into the remote server specified and then, remotely on the server itself, starts a nested Tmux session. So we have one Tmux session on the local computer and, inside of it, an SSH connection to a remote server with a Tmux session running again. The benefit of this is that, in case my network connection breaks down, the next time I connect, I can continue my work on the remote server exactly where I left off. The session name is the name of the server being SSHed into. If a session like this already exists, it simply attaches to it.
+
+
+function tmux::remote
+ set -l server $argv[1]
+ tmux new -s $server "ssh -A -t $server 'tmux attach-session || tmux'" || tmux attach-session -d -t $server
+end
+
+
+Change of the Tmux prefix for better nesting
+
+To make nested Tmux sessions work smoothly, one must change the Tmux prefix key locally or remotely. By default, the Tmux prefix key is Ctrl-b, so Ctrl-b $, for example, renames the current session. To change the prefix key from the standard Ctrl-b to, for example, Ctrl-g, you must add this to the tmux.conf:
+
+
+set-option -g prefix C-g
+
+
+This way, when I want to rename the remote Tmux session, I have to use Ctrl-g $, and when I want to rename the local Tmux session, I still have to use Ctrl-b $. In my case, I have this deployed to all remote servers through a configuration management system (out of scope for this blog post).
+
+There might also be another way around this (without reconfiguring the prefix key), but that is cumbersome to use, as far as I remember.
+
+The ts alias - Searching sessions with fuzzy finder
+
+Despite the fact that with _tmux::cleanup_default, I don't leave a huge mess with trillions of Tmux sessions flying around all the time, at times, it can become challenging to find exactly the session I am currently interested in. After a busy workday, I often end up with around twenty sessions on my laptop. This is where fuzzy searching for session names comes in handy, as I often don't remember the exact session names.
+
+
+function tmux::search
+ set -l session (tmux list-sessions | fzf | cut -d: -f1)
+ if test -z "$TMUX"
+ tmux attach-session -t $session
+ else
+ tmux switch -t $session
+ end
+end
+
+
+All it does is list all currently open sessions in fzf, where one of them can be searched and selected through fuzzy find, and then either switch (if already inside a session) to the other session or attach to the other session (if not yet in Tmux).
+
+You must install the fzf command on your computer for this to work. This is how it looks like:
+
+
+
+The tssh alias - Cluster SSH replacement
+
+Before I used Tmux, I was a heavy user of ClusterSSH, which allowed me to log in to multiple servers at once in a single terminal window and type and run commands on all of them in parallel.
+
+https://github.com/duncs/clusterssh
+
+However, since I started using Tmux, I retired ClusterSSH, as it came with the benefit that Tmux only needs to be run in the terminal, whereas ClusterSSH spawned terminal windows, which aren't easily portable (e.g., from a Linux desktop to macOS). The tmux::cluster_ssh function can have N arguments, where:
+
+
+
+This is the function definition behind the tssh alias:
+
+
+function tmux::cluster_ssh
+ if test -f "$argv[1]"
+ tmux::tssh_from_file $argv[1]
+ return
+ end
+ tmux::tssh_from_argument $argv
+end
+
+
+This function is just a wrapper around the more complex tmux::tssh_from_file and tmux::tssh_from_argument functions, as you have learned already. Most of the magic happens there.
+
+The tmux::tssh_from_argument helper
+
+This is the most magic helper function we will cover in this post. It looks like this:
+
+
+function tmux::tssh_from_argument
+ set -l session $argv[1]
+ set first_server_or_container $argv[2]
+ set remaining_servers $argv[3..-1]
+ if test -z "$first_server_or_container"
+ set first_server_or_container $session
+ end
+
+ tmux new-session -d -s $session (_tmux::connect_command "$first_server_or_container")
+ if not tmux list-session | grep "^$session:"
+ echo "Could not create session $session"
+ return 2
+ end
+ for server_or_container in $remaining_servers
+ tmux split-window -t $session "tmux select-layout tiled; $(_tmux::connect_command "$server_or_container")"
+ end
+ tmux setw -t $session synchronize-panes on
+ tmux -2 attach-session -t $session || tmux -2 switch-client -t $session
+end
+
+
+It expects at least two arguments. The first argument is the session name to create for the clustered SSH session. All other arguments are server hostnames or FQDNs to which to connect. The first one is used to make the initial session. All remaining ones are added to that session with tmux split-window -t $session.... At the end, we enable synchronized panes by default, so whenever you type, the commands will be sent to every SSH connection, thus allowing the neat ClusterSSH feature to run commands on multiple servers simultaneously. Once done, we attach (or switch, if already in Tmux) to it.
+
+Sometimes, I don't want the synchronized panes behavior and want to switch it off temporarily. I can do that with prefix-key p and prefix-key P after adding the following to my local tmux.conf:
+
+
+bind-key p setw synchronize-panes off
+bind-key P setw synchronize-panes on
+
+
+The tmux::tssh_from_file helper
+
+This one sets the session name to the file name and then reads a list of servers from that file, passing the list of servers to tmux::tssh_from_argument as the arguments. So, this is a neat little wrapper that also enables me to open clustered SSH sessions from an input file.
+
+
+function tmux::tssh_from_file
+ set -l serverlist $argv[1]
+ set -l session (basename $serverlist | cut -d. -f1)
+ tmux::tssh_from_argument $session (awk '{ print $1 }' $serverlist | sed 's/.lan./.lan/g')
+end
+
+
+tssh examples
+
+To open a new session named fish and log in to 4 remote hosts, run this command (Note that it is also possible to specify the remote user):
+
+
+$ tssh fish blowfish.buetow.org fishfinger.buetow.org \
+ fishbone.buetow.org user@octopus.buetow.org
+
+
+To open a new session named manyservers, put many servers (one FQDN per line) into a file called manyservers.txt and simply run:
+
+
+$ tssh manyservers.txt
+
+
+Common Tmux commands I use in tssh
+
+These are default Tmux commands that I make heavy use of in a tssh session:
+
+
+
+Copy and paste workflow
+
+As you will see later in this blog post, I have configured a history limit of 1 million items in Tmux so that I can scroll back quite far. One main workflow of mine is to search for text in the Tmux history, select and copy it, and then switch to another window or session and paste it there (e.g., into my text editor to do something with it).
+
+This works by pressing prefix-key [ to enter Tmux copy mode. From there, I can browse the Tmux history of the current window using either the arrow keys or vi-like navigation (see vi configuration later in this blog post) and the Pg-Dn and Pg-Up keys.
+
+I often search the history backwards with prefix-key [ followed by a ?, which opens the Tmux history search prompt.
+
+Once I have identified the terminal text to be copied, I enter visual select mode with v, highlight all the text to be copied (using arrow keys or Vi motions), and press y to yank it (sorry if this all sounds a bit complicated, but Vim/NeoVim users will know this, as it is pretty much how you do it there as well).
+
+For v and y to work, the following has to be added to the Tmux configuration file:
+
+
+bind-key -T copy-mode-vi 'v' send -X begin-selection
+bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
+
+
+Once the text is yanked, I switch to another Tmux window or session where, for example, a text editor is running and paste the yanked text from Tmux into the editor with prefix-key ]. Note that when pasting into a modal text editor like Vi or Helix, you would first need to enter insert mode before prefix-key ] would paste anything.
+
+Tmux configurations
+
+Some features I have configured directly in Tmux don't require an external shell alias to function correctly. Let's walk line by line through my local ~/.config/tmux/tmux.conf:
+
+
+source ~/.config/tmux/tmux.local.conf
+
+set-option -g allow-rename off
+set-option -g history-limit 100000
+set-option -g status-bg '#444444'
+set-option -g status-fg '#ffa500'
+set-option -s escape-time 0
+
+
+There's yet to be much magic happening here. I source a tmux.local.conf, which I sometimes use to override the default configuration that comes from the configuration management system. But it is mostly just an empty file, so it doesn't throw any errors on Tmux startup when I don't use it.
+
+I work with many terminal outputs, which I also like to search within Tmux. So, I added a large enough history-limit, enabling me to search backwards in Tmux for any output up to a million lines of text.
+
+Besides changing some colours (personal taste), I also set escape-time to 0, which is just a workaround. Otherwise, my Helix text editor's ESC key would take ages to trigger within Tmux. I am trying to remember the gory details. You can leave it out; if everything works fine for you, leave it out.
+
+The next lines in the configuration file are:
+
+
+set-window-option -g mode-keys vi
+bind-key -T copy-mode-vi 'v' send -X begin-selection
+bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
+
+
+I navigate within Tmux using Vi keybindings, so the mode-keys is set to vi. I use the Helix modal text editor, which is close enough to Vi bindings for simple navigation to feel "native" to me. (By the way, I have been a long-time Vim and NeoVim user, but I eventually switched to Helix. It's off-topic here, but it may be worth another blog post once.)
+
+The two bind-key commands make it so that I can use v and y in copy mode, which feels more Vi-like (as already discussed earlier in this post).
+
+The next set of lines in the configuration file are:
+
+
+bind-key h select-pane -L
+bind-key j select-pane -D
+bind-key k select-pane -U
+bind-key l select-pane -R
+
+bind-key H resize-pane -L 5
+bind-key J resize-pane -D 5
+bind-key K resize-pane -U 5
+bind-key L resize-pane -R 5
+
+
+These allow me to use prefix-key h, prefix-key j, prefix-key k, and prefix-key l for switching panes and prefix-key H, prefix-key J, prefix-key K, and prefix-key L for resizing the panes. If you don't know Vi/Vim/NeoVim, the letters hjkl are commonly used there for left, down, up, and right, which is also the same for Helix, by the way.
+
+The next set of lines in the configuration file are:
+
+
+bind-key c new-window -c '#{pane_current_path}'
+bind-key F new-window -n "session-switcher" "tmux list-sessions | fzf | cut -d: -f1 | xargs tmux switch-client -t"
+bind-key T choose-tree
+
+
+The first one is that any new window starts in the current directory. The second one is more interesting. I list all open sessions in the fuzzy finder. I rely heavily on this during my daily workflow to switch between various sessions depending on the task. E.g. from a remote cluster SSH session to a local code editor.
+
+The third one, choose-tree, opens a tree view in Tmux listing all sessions and windows. This one is handy to get a better overview of what is currently running in any local Tmux session. It looks like this (it also allows me to press a hotkey to switch to a particular Tmux window):
+
+
+
+The last remaining lines in my configuration file are:
+
+
+bind-key p setw synchronize-panes off
+bind-key P setw synchronize-panes on
+bind-key r source-file ~/.config/tmux/tmux.conf \; display-message "tmux.conf reloaded"
+
+
+We discussed synchronized panes earlier. I use it all the time in clustered SSH sessions. When enabled, all panes (remote SSH sessions) receive the same keystrokes. This is very useful when you want to run the same commands on many servers at once, such as navigating to a common directory, restarting a couple of services at once, or running tools like htop to quickly monitor system resources.
+
+The last one reloads my Tmux configuration on the fly.
+
+E-Mail your comments to paul@nospam.buetow.org :-)
+
+Back to the main site
+
+
+
diff --git a/gemfeed/atom.xml b/gemfeed/atom.xml
index d4743e21..2d582f88 100644
--- a/gemfeed/atom.xml
+++ b/gemfeed/atom.xml
@@ -1,11 +1,414 @@
Terminal multiplexing with tmux - Fish edition
+
+This is the Fish shell edition of the same post of mine from last year:
+
+./2024-06-23-terminal-multiplexing-with-tmux.html
+
+Tmux (Terminal Multiplexer) is a powerful, terminal-based tool that manages multiple terminal sessions within a single window. Here are some of its primary features and functionalities:
+
+
+
+https://github.com/tmux/tmux/wiki
+
+
+ _______
+ |.-----.|
+ || Tmux||
+ ||_.-._||
+ `--)-(--`
+ __[=== o]___
+ |:::::::::::|\
+jgs `-=========-`()
+ mod. by Paul B.
+
+
+Table of Contents
+
+
+
+Before continuing...
+
+Before continuing to read this post, I encourage you to get familiar with Tmux first (unless you already know the basics). You can go through the official getting started guide:
+
+https://github.com/tmux/tmux/wiki/Getting-Started
+
+I can also recommend this book (this is the book I got started with with Tmux):
+
+https://pragprog.com/titles/bhtmux2/tmux-2/
+
+Over the years, I have built a couple of shell helper functions to optimize my workflows. Tmux is extensively integrated into my daily workflows (personal and work). I had colleagues asking me about my Tmux config and helper scripts for Tmux several times. It would be neat to blog about it so that everyone interested in it can make a copy of my configuration and scripts.
+
+The configuration and scripts in this blog post are only the non-work-specific parts. There are more helper scripts, which I only use for work (and aren't really useful outside of work due to the way servers and clusters are structured there).
+
+Tmux is highly configurable, and I think I am only scratching the surface of what is possible with it. Nevertheless, it may still be useful for you. I also love that Tmux is part of the OpenBSD base system!
+
+Shell aliases
+
+Since last week, I switched to the Fish shell. As a result, I also had to convert all my tmux helper scripts (mentioned in this blog post) to Fish.
+
+https://fishshell.com
+
+For the most common Tmux commands I use, I have created the following shell aliases:
+
+
+alias tn 'tmux::new'
+alias ta 'tmux::attach'
+alias tx 'tmux::remote'
+alias ts 'tmux::search'
+alias tssh 'tmux::cluster_ssh'
+alias tm tmux
+alias tl 'tmux list-sessions'
+alias foo 'tmux::new foo'
+alias bar 'tmux::new bar'
+alias baz 'tmux::new baz'
+
+
+Note all tmux::...; those are custom shell functions doing certain things, and they aren't part of the Tmux distribution. But let's run through every aliases one by one.
+
+The first two are pretty straightforward. tm is simply a shorthand for tmux, so I have to type less, and tl lists all Tmux sessions that are currently open. No magic here.
+
+The tn alias - Creating a new session
+
+The tn alias is referencing this function:
+
+
+# Create new session and if alread exists attach to it
+function tmux::new
+ set -l session $argv[1]
+ _tmux::cleanup_default
+ if test -z "$session"
+ tmux::new (string join "" T (date +%s))
+ else
+ tmux new-session -d -s $session
+ tmux -2 attach-session -t $session || tmux -2 switch-client -t $session
+ end
+end
+
+
+There is a lot going on here. Let's have a detailed look at what it is doing.
+
+First, a Tmux session name can be passed to the function as a first argument. That session name is only optional. Without it, Tmux will select a session named (string join "" T (date +%s)) as a default. Which is T followed by the UNIX epoch, e.g. T1717133796.
+
+Cleaning up default sessions automatically
+
+Note also the call to _tmux::cleanup_default; it would clean up all already opened default sessions if they aren't attached. Those sessions were only temporary, and I had too many flying around after a while. So, I decided to auto-delete the sessions if they weren't attached. If I want to keep sessions around, I will rename them with the Tmux command prefix-key $. This is the cleanup function:
+
+
+function _tmux::cleanup_default
+ tmux list-sessions | string match -r '^T.*: ' | string match -v -r attached | string split ':' | while read -l s
+ echo "Killing $s"
+ tmux kill-session -t "$s"
+ end
+end
+
+
+The cleanup function kills all open Tmux sessions that haven't been renamed properly yet—but only if they aren't attached (e.g., don't run in the foreground in any terminal). Cleaning them up automatically keeps my Tmux sessions as neat and tidy as possible.
+
+Renaming sessions
+
+Whenever I am in a temporary session (named T....), I may decide that I want to keep this session around. I have to rename the session to prevent the cleanup function from doing its thing. That's, as mentioned already, easily accomplished with the standard prefix-key $ Tmux command.
+
+The ta alias - Attaching to a session
+
+This alias refers to the following function, which tries to attach to an already-running Tmux session.
+
+
+function tmux::attach
+ set -l session $argv[1]
+ if test -z "$session"
+ tmux attach-session || tmux::new
+ else
+ tmux attach-session -t $session || tmux::new $session
+ end
+end
+
+
+If no session is specified (as the argument of the function), it will try to attach to the first open session. If no Tmux server is running, it will create a new one with tmux::new. Otherwise, with a session name given as the argument, it will attach to it. If unsuccessful (e.g., the session doesn't exist), it will be created and attached to.
+
+The tr alias - For a nested remote session
+
+This SSHs into the remote server specified and then, remotely on the server itself, starts a nested Tmux session. So we have one Tmux session on the local computer and, inside of it, an SSH connection to a remote server with a Tmux session running again. The benefit of this is that, in case my network connection breaks down, the next time I connect, I can continue my work on the remote server exactly where I left off. The session name is the name of the server being SSHed into. If a session like this already exists, it simply attaches to it.
+
+
+function tmux::remote
+ set -l server $argv[1]
+ tmux new -s $server "ssh -A -t $server 'tmux attach-session || tmux'" || tmux attach-session -d -t $server
+end
+
+
+Change of the Tmux prefix for better nesting
+
+To make nested Tmux sessions work smoothly, one must change the Tmux prefix key locally or remotely. By default, the Tmux prefix key is Ctrl-b, so Ctrl-b $, for example, renames the current session. To change the prefix key from the standard Ctrl-b to, for example, Ctrl-g, you must add this to the tmux.conf:
+
+
+set-option -g prefix C-g
+
+
+This way, when I want to rename the remote Tmux session, I have to use Ctrl-g $, and when I want to rename the local Tmux session, I still have to use Ctrl-b $. In my case, I have this deployed to all remote servers through a configuration management system (out of scope for this blog post).
+
+There might also be another way around this (without reconfiguring the prefix key), but that is cumbersome to use, as far as I remember.
+
+The ts alias - Searching sessions with fuzzy finder
+
+Despite the fact that with _tmux::cleanup_default, I don't leave a huge mess with trillions of Tmux sessions flying around all the time, at times, it can become challenging to find exactly the session I am currently interested in. After a busy workday, I often end up with around twenty sessions on my laptop. This is where fuzzy searching for session names comes in handy, as I often don't remember the exact session names.
+
+
+function tmux::search
+ set -l session (tmux list-sessions | fzf | cut -d: -f1)
+ if test -z "$TMUX"
+ tmux attach-session -t $session
+ else
+ tmux switch -t $session
+ end
+end
+
+
+All it does is list all currently open sessions in fzf, where one of them can be searched and selected through fuzzy find, and then either switch (if already inside a session) to the other session or attach to the other session (if not yet in Tmux).
+
+You must install the fzf command on your computer for this to work. This is how it looks like:
+
+
+
+The tssh alias - Cluster SSH replacement
+
+Before I used Tmux, I was a heavy user of ClusterSSH, which allowed me to log in to multiple servers at once in a single terminal window and type and run commands on all of them in parallel.
+
+https://github.com/duncs/clusterssh
+
+However, since I started using Tmux, I retired ClusterSSH, as it came with the benefit that Tmux only needs to be run in the terminal, whereas ClusterSSH spawned terminal windows, which aren't easily portable (e.g., from a Linux desktop to macOS). The tmux::cluster_ssh function can have N arguments, where:
+
+
+
+This is the function definition behind the tssh alias:
+
+
+function tmux::cluster_ssh
+ if test -f "$argv[1]"
+ tmux::tssh_from_file $argv[1]
+ return
+ end
+ tmux::tssh_from_argument $argv
+end
+
+
+This function is just a wrapper around the more complex tmux::tssh_from_file and tmux::tssh_from_argument functions, as you have learned already. Most of the magic happens there.
+
+The tmux::tssh_from_argument helper
+
+This is the most magic helper function we will cover in this post. It looks like this:
+
+
+function tmux::tssh_from_argument
+ set -l session $argv[1]
+ set first_server_or_container $argv[2]
+ set remaining_servers $argv[3..-1]
+ if test -z "$first_server_or_container"
+ set first_server_or_container $session
+ end
+
+ tmux new-session -d -s $session (_tmux::connect_command "$first_server_or_container")
+ if not tmux list-session | grep "^$session:"
+ echo "Could not create session $session"
+ return 2
+ end
+ for server_or_container in $remaining_servers
+ tmux split-window -t $session "tmux select-layout tiled; $(_tmux::connect_command "$server_or_container")"
+ end
+ tmux setw -t $session synchronize-panes on
+ tmux -2 attach-session -t $session || tmux -2 switch-client -t $session
+end
+
+
+It expects at least two arguments. The first argument is the session name to create for the clustered SSH session. All other arguments are server hostnames or FQDNs to which to connect. The first one is used to make the initial session. All remaining ones are added to that session with tmux split-window -t $session.... At the end, we enable synchronized panes by default, so whenever you type, the commands will be sent to every SSH connection, thus allowing the neat ClusterSSH feature to run commands on multiple servers simultaneously. Once done, we attach (or switch, if already in Tmux) to it.
+
+Sometimes, I don't want the synchronized panes behavior and want to switch it off temporarily. I can do that with prefix-key p and prefix-key P after adding the following to my local tmux.conf:
+
+
+bind-key p setw synchronize-panes off
+bind-key P setw synchronize-panes on
+
+
+The tmux::tssh_from_file helper
+
+This one sets the session name to the file name and then reads a list of servers from that file, passing the list of servers to tmux::tssh_from_argument as the arguments. So, this is a neat little wrapper that also enables me to open clustered SSH sessions from an input file.
+
+
+function tmux::tssh_from_file
+ set -l serverlist $argv[1]
+ set -l session (basename $serverlist | cut -d. -f1)
+ tmux::tssh_from_argument $session (awk '{ print $1 }' $serverlist | sed 's/.lan./.lan/g')
+end
+
+
+tssh examples
+
+To open a new session named fish and log in to 4 remote hosts, run this command (Note that it is also possible to specify the remote user):
+
+
+$ tssh fish blowfish.buetow.org fishfinger.buetow.org \
+ fishbone.buetow.org user@octopus.buetow.org
+
+
+To open a new session named manyservers, put many servers (one FQDN per line) into a file called manyservers.txt and simply run:
+
+
+$ tssh manyservers.txt
+
+
+Common Tmux commands I use in tssh
+
+These are default Tmux commands that I make heavy use of in a tssh session:
+
+
+
+Copy and paste workflow
+
+As you will see later in this blog post, I have configured a history limit of 1 million items in Tmux so that I can scroll back quite far. One main workflow of mine is to search for text in the Tmux history, select and copy it, and then switch to another window or session and paste it there (e.g., into my text editor to do something with it).
+
+This works by pressing prefix-key [ to enter Tmux copy mode. From there, I can browse the Tmux history of the current window using either the arrow keys or vi-like navigation (see vi configuration later in this blog post) and the Pg-Dn and Pg-Up keys.
+
+I often search the history backwards with prefix-key [ followed by a ?, which opens the Tmux history search prompt.
+
+Once I have identified the terminal text to be copied, I enter visual select mode with v, highlight all the text to be copied (using arrow keys or Vi motions), and press y to yank it (sorry if this all sounds a bit complicated, but Vim/NeoVim users will know this, as it is pretty much how you do it there as well).
+
+For v and y to work, the following has to be added to the Tmux configuration file:
+
+
+bind-key -T copy-mode-vi 'v' send -X begin-selection
+bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
+
+
+Once the text is yanked, I switch to another Tmux window or session where, for example, a text editor is running and paste the yanked text from Tmux into the editor with prefix-key ]. Note that when pasting into a modal text editor like Vi or Helix, you would first need to enter insert mode before prefix-key ] would paste anything.
+
+Tmux configurations
+
+Some features I have configured directly in Tmux don't require an external shell alias to function correctly. Let's walk line by line through my local ~/.config/tmux/tmux.conf:
+
+
+source ~/.config/tmux/tmux.local.conf
+
+set-option -g allow-rename off
+set-option -g history-limit 100000
+set-option -g status-bg '#444444'
+set-option -g status-fg '#ffa500'
+set-option -s escape-time 0
+
+
+There's yet to be much magic happening here. I source a tmux.local.conf, which I sometimes use to override the default configuration that comes from the configuration management system. But it is mostly just an empty file, so it doesn't throw any errors on Tmux startup when I don't use it.
+
+I work with many terminal outputs, which I also like to search within Tmux. So, I added a large enough history-limit, enabling me to search backwards in Tmux for any output up to a million lines of text.
+
+Besides changing some colours (personal taste), I also set escape-time to 0, which is just a workaround. Otherwise, my Helix text editor's ESC key would take ages to trigger within Tmux. I am trying to remember the gory details. You can leave it out; if everything works fine for you, leave it out.
+
+The next lines in the configuration file are:
+
+
+set-window-option -g mode-keys vi
+bind-key -T copy-mode-vi 'v' send -X begin-selection
+bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
+
+
+I navigate within Tmux using Vi keybindings, so the mode-keys is set to vi. I use the Helix modal text editor, which is close enough to Vi bindings for simple navigation to feel "native" to me. (By the way, I have been a long-time Vim and NeoVim user, but I eventually switched to Helix. It's off-topic here, but it may be worth another blog post once.)
+
+The two bind-key commands make it so that I can use v and y in copy mode, which feels more Vi-like (as already discussed earlier in this post).
+
+The next set of lines in the configuration file are:
+
+
+bind-key h select-pane -L
+bind-key j select-pane -D
+bind-key k select-pane -U
+bind-key l select-pane -R
+
+bind-key H resize-pane -L 5
+bind-key J resize-pane -D 5
+bind-key K resize-pane -U 5
+bind-key L resize-pane -R 5
+
+
+These allow me to use prefix-key h, prefix-key j, prefix-key k, and prefix-key l for switching panes and prefix-key H, prefix-key J, prefix-key K, and prefix-key L for resizing the panes. If you don't know Vi/Vim/NeoVim, the letters hjkl are commonly used there for left, down, up, and right, which is also the same for Helix, by the way.
+
+The next set of lines in the configuration file are:
+
+
+bind-key c new-window -c '#{pane_current_path}'
+bind-key F new-window -n "session-switcher" "tmux list-sessions | fzf | cut -d: -f1 | xargs tmux switch-client -t"
+bind-key T choose-tree
+
+
+The first one is that any new window starts in the current directory. The second one is more interesting. I list all open sessions in the fuzzy finder. I rely heavily on this during my daily workflow to switch between various sessions depending on the task. E.g. from a remote cluster SSH session to a local code editor.
+
+The third one, choose-tree, opens a tree view in Tmux listing all sessions and windows. This one is handy to get a better overview of what is currently running in any local Tmux session. It looks like this (it also allows me to press a hotkey to switch to a particular Tmux window):
+
+
+
+The last remaining lines in my configuration file are:
+
+
+bind-key p setw synchronize-panes off
+bind-key P setw synchronize-panes on
+bind-key r source-file ~/.config/tmux/tmux.conf \; display-message "tmux.conf reloaded"
+
+
+We discussed synchronized panes earlier. I use it all the time in clustered SSH sessions. When enabled, all panes (remote SSH sessions) receive the same keystrokes. This is very useful when you want to run the same commands on many servers at once, such as navigating to a common directory, restarting a couple of services at once, or running tools like htop to quickly monitor system resources.
+
+The last one reloads my Tmux configuration on the fly.
+
+E-Mail your comments to paul@nospam.buetow.org :-)
+
+Back to the main site
+ Terminal multiplexing with tmux
+ Terminal multiplexing with tmux - Z-Shell edition
-Published at 2024-06-23T22:41:59+03:00
+Published at 2024-06-23T22:41:59+03:00; Last updated 2025-05-02
+
+This is the Z-Shell version. There is also a Fish version:
+
+./2025-05-02-terminal-multiplexing-with-tmux-fish-edition.html
Tmux (Terminal Multiplexer) is a powerful, terminal-based tool that manages multiple terminal sessions within a single window. Here are some of its primary features and functionalities:
@@ -4337,7 +4744,7 @@ jgs `-=========-`()
Table of Contents
-
E-Mail your comments to paul@nospam.buetow.org :-)
-Back to the main site
- (Re)learning Java - My takeaways
-
-Published at 2022-12-24T23:18:40+02:00
-
-As a regular participant in the annual Pet Project competition at work, I always try to find a project where I can learn something new. In this post, I would like to share my takeaways after revisiting Java. You can read about my motivations in my "Creative universe" post:
-
-Creative universe
-
-I have been programming in Java back in the days as a university student, and even my Diploma Thesis I implemented in Java (it would require some overhaul so that it is fully compatible with a recent version of Java, though - It still compiles and runs, but with a lot of warnings, though!):
-
-VS-Sim: Distributed systems simulator
-
-However, after that, I became a Linux Sysadmin and mainly continued programming in Perl, Puppet, bash, and a little Python. For personal use, I also programmed a bit in Haskell and C. After my Sysadmin role, I moved to London and became a Site Reliability Engineer (SRE), where I mainly programmed in Ruby, bash, Puppet and Golang and a little bit of C.
-
-At my workplace, as an SRE, I don't do Java a lot. I have been reading Java code to understand the software better so I can apply and suggest workarounds or fixes to existing issues and bugs. However, most of our stack is in Java, and our Software Engineers use Java as their primary programming language.
-
-
-
-Table of Contents
-
-
-
-Stuck at Java 1.4
-
-Over time, I had been missing out on many new features that were added to the language since Java 1.4, so I decided to implement my next Pet Project in Java and learn every further aspect of the language as my main goal. Of course, I still liked the idea of winning a Pet Project Prize, but my main objective was to level up my Java skills.
-
-(Re)learning & upskilling to Java 18
-
-Effective Java
-
-This book was recommended by my brother and also by at least another colleague at work to be one of the best, if not the best, book about Java programming. I read the whole book from the beginning to the end and immersed myself in it. I fully agree; this is a great book. Every Java developer or Java software engineer should read it!
-
-
-
-I recommend reading the 90-part effective Java Series on dev.to. It's a perfect companion to the book as it explains all the chapters again but from a slightly different perspective and helps you to really understand the content.
-
-Kyle Carter's 90-part Effective Java Series
-
-Java Pub House
-
-During my lunch breaks, I usually have a walk around the block or in a nearby park. I used that time to listen to the Java Pub House podcast. I listened to *every* episode and learned tons of new stuff. I can highly recommend this podcast. Especially GraalVM, a high-performance JDK distribution written for Java and other JVM languages, captured my attention. GraalVM can compile Java code into native binaries, improving performance and easing the distribution of Java programs. Because of the latter, I should release a VS-Sim GraalVM edition one day through a Linux AppImage ;-).
-
-https://www.javapubhouse.com
-https://www.graalvm.org
-
-Java Concurrency course
-
-I also watched a course on O'Reilly Safari Books online about Java Concurrency. That gave an excellent refresher on how the Java thread pools work and what were the concurrency primitives available in the standard library.
-
-Read a lot of Java code
-
-First, the source code is often the best documentation (if programmed nicely), and second, it helps to get the hang of the language and standard practices. I started to read more and more Java code at work. I did that whenever I had to understand how something, in particular, worked (e.g. while troubleshooting and debugging an issue).
-
-Observed Java code reviews
-
-Another great way to get the hang of Java again was to sneak into the code reviews of the Software Engineer colleagues. They are the expert on the matter and are a great source to copy knowledge. It's OK to stay passive and only follow the reviews. Sometimes, it's OK to step up and take ownership of the review. The developers will also always be happy to answer any naive questions which come up.
-
-Took ownership of a roadmap-Java project
-
-Besides my Pet Project, I also took ownership of a regular roadmap Java project at work, making an internal Java service capable of running in Kubernetes. This was a bunch of minor changes and adding a bunch of classes and unit tests dealing with the statelessness and a persistent job queue in Redis. The job also involved reading and understanding a lot of already existing Java code. It wasn't part of my job description, but it was fun, and I learned a lot. The service runs smoothly in production now. Of course, all of my code got reviewed by my Software Engineering colleagues.
-
-The good
-
-From the new language features and syntaxes, there are many personal takeaways, and I can't possibly list them all, but here are some of my personal highlights:
-
-
-
-The bad and the ugly
-
-There are also many ugly corners in Java. Many are doomed to stay there forever due to historical decisions and ensuring backward compatibility with older versions of the Java language and the Java standard library.
-
-
-
-
-Conclusion
-
-While (re)learning Java, I felt like a student again and was quite enthusiastic about it initially. I invested around half a year, immersing myself intensively in Java (again). The last time I did that was many years ago as a university student. I even won a Silver Prize at work, implementing a project this year (2022 as of writing this). I feel confident now with understanding, debugging and patching Java code at work, which boosted my debugging and troubleshooting skills.
-
-I don't hate Java, but I don't love programming in it, either. I will, I guess, always see Java as the necessary to get stuff done (reading code to understand how the service works, adding a tiny feature to make my life easier, adding a quick bug fix to overcome an obstacle...).
-
-Although Java has significantly improved since 1.4, its code still tends to be more boilerplate. Not mainly because due to lines of code (Golang code tends to be quite repetitive, primarily when no generics are used), but due to the levels of abstractions it uses. Class hierarchies can be ten classes or deeper, and it is challenging to understand what the code is doing. Good test coverage and much documentation can mitigate the problem partially. Big enterprises use Java, and that also reflects to the language. There are too many libraries and too many abstractions that are bundled with too many legacy abstractions and interfaces and too many exceptions in the library APIs. There's even an external library named Lombok, which aims to reduce Java boilerplate code. Why is there a need for an external library? It should be all part of Java itself.
-
-https://projectlombok.org/
-
-Java needs a clean cut. The clean cut shall be incompatible with previous versions of Java and only promote modern best practices without all the legacy burden carried around. The same can be said for other languages, e.g. Perl, but in Perl, they already attack the problem with the use of flags which change the behaviour of the language to more modern standards. Or do it like Python, where they had a hard (incompatible) cut from version 2 to version 3. It will be painful, for sure. But that would be the only way I would enjoy using that language as one of my primary languages to code new stuff regularly. Currently, my Java will stay limited to very few projects and the more minor things already mentioned in this post.
-
-Am I a Java expert now? No, by far not. But I am better now than before :-).
-
-E-Mail your comments to paul@nospam.buetow.org :-)
-
Back to the main site
To be in the .zone!
+2025-05-02 - Terminal multiplexing with tmux - Fish edition
2025-04-19 - 'When: The Scientific Secrets of Perfect Timing' book notes
2025-04-05 - f3s: Kubernetes with FreeBSD - Part 4: Rocky Linux Bhyve VMs
2025-03-05 - Sharing on Social Media with Gos v1.0.0
@@ -32,7 +33,7 @@
2024-08-05 - Typing 127.1 words per minute (>100wpm average)
2024-07-07 - 'The Stoic Challenge' book notes
2024-07-05 - Random Weird Things - Part Ⅰ
-2024-06-23 - Terminal multiplexing with tmux
+2024-06-23 - Terminal multiplexing with tmux - Z-Shell edition
2024-05-03 - Projects I currently don't have time for
2024-05-01 - 'Slow Productivity' book notes
2024-04-01 - KISS high-availability with OpenBSD
diff --git a/index.html b/index.html
index fc487966..e28bfe04 100644
--- a/index.html
+++ b/index.html
@@ -13,7 +13,7 @@