summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemfeed/DRAFT-terminal-multiplexing-with-tmux.gmi85
1 files changed, 42 insertions, 43 deletions
diff --git a/gemfeed/DRAFT-terminal-multiplexing-with-tmux.gmi b/gemfeed/DRAFT-terminal-multiplexing-with-tmux.gmi
index 1bb2efef..56d0ffce 100644
--- a/gemfeed/DRAFT-terminal-multiplexing-with-tmux.gmi
+++ b/gemfeed/DRAFT-terminal-multiplexing-with-tmux.gmi
@@ -2,40 +2,40 @@
## Introduction
-Tmux (Terminal Multiplexer) is a powerful, terminal-based tool that allows to manage multiple terminal sessions within a single window. Here are some of its primary features and functionalities:
+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:
* Session management
* Window and Pane management
-* Persistent Workspacec
+* Persistent Workspace
* Customization
=> https://github.com/tmux/tmux/wiki
-Before continuing reading this post, I encourage to get familiar with Tmux first (unless, of course, you know already the basics). You could go through the official getting started guide:
+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 recommendc this book (this is the book I got started with with Tmux):
+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 build a couple of shell helper functions to optimize my workflows.
+Over the years, I have built a couple of shell helper functions to optimize my workflows.
-Tmux is integrated into my daily workflows (personal and work) a lot. I had colleagues asking me about my Tmux config and helper scripts for Tmux a couple of times. I thought it would be neat to blog about it, so that everyone who is interested in it, can make a copy of my configuration and scripts.
+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 the 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 nature how servers and clusters are structured there).
+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 surfice with what is possible with it. Nethertheless, it may be still useful for you.
+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 the fact that Tmux is actually part of the OpenBSD base system!
+I also love that Tmux is part of the OpenBSD base system!
## Shell aliases
-I am a user of the Z-Shell (`zsh`) but I believe all the snippets mentioned in this blog post also work with Bash.
+I am a user of the Z-Shell (`zsh`), but I believe all the snippets mentioned in this blog post also work with Bash.
=> https://www.zsh.org
-For the most common tmux commands I use I have created the following shell aliases:
+For the most common Tmux commands I use, I have created the following shell aliases:
```bash
alias tm=tmux
@@ -47,9 +47,9 @@ alias ts=tmux::search
alias tssh=tmux::cluster_ssh
```
-Note all `tmux::...`, those are custom shell functions doing certain things, those aren't part of the Tmux distribution. But let's run through every alias one-by-one.
+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 straight forward. `tm` is simply a shorthand for `tmux`, so I have to type less and `tl` simply lists all Tmux sessions currently open. Not much magic here.
+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. Only a little magic here.
## The `tn` alias - Creating a new session
@@ -75,13 +75,13 @@ tmux::new () {
alias tn=tmux::new
```
-There is a lot of stuff going on here. Let's have a look in detail what it is doing. As a note, the function relies on GNU Date, so for MacOS it is looking for the `gdate` commands to be available. Otherwise, it will fallback to `date`. For Mac, you would need to install GNU Date as it isn't installed by default there. As I use Fedora Linux on my personal Laptop and a MacBook for work, I have to make it work for both.
+There is a lot going on here. Let's have a detailed look at what it is doing. As a note, the function relies on GNU Date, so MacOS is looking for the `gdate` commands to be available. Otherwise, it will fall back to `date`. You need to install GNU Date for Mac, as it isn't installed by default there. As I use Fedora Linux on my personal Laptop and a MacBook for work, I have to make it work for both.
-First, as a first argument, a Tmux session name can be passed to the function. That session name is only optional. Without it, Tmux will select a session named `T$($date +%s)` as a default. Which is T followed by the UNIX epoch, e.g. `T1717133796`.
+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 `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 kind of sessions are only of temporal nature and I found myself that I had too many flying around after a while. So I decided to auto delete the sessions if they aren't still attached. If I want to keep sessions around I would rename them with the Tmux command `prefix-key $`. This is the cleanup function:
+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:
```bash
tmux::cleanup_default () {
@@ -94,15 +94,15 @@ tmux::cleanup_default () {
}
```
-The cleanup function kills all open Tmux session which haven't beren 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 it gets.
+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. To avoid the cleanup function from doing its thing, I have to rename the session. That's easily accomplished with the standard `prefix-key $` Tmux command.
+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 easily accomplished with the standard `prefix-key $` Tmux command.
## The `ta` alias - Attaching to a session
-This alias refers to the following function, which simply tries to attach to an already-running Tmux session.
+This alias refers to the following function, which tries to attach to an already-running Tmux session.
```bash
tmux::attach () {
@@ -117,7 +117,7 @@ tmux::attach () {
alias ta=tmux::attach
```
-If there is no session specified (as the argument of the function), it will try to attach to the first open session. If there is no Tmux server 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. session doesn't exist), it will be created and attached to.
+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
@@ -134,7 +134,7 @@ alias tr=tmux::remote
### Change of the Tmux prefix for better nesting
-In order to make nested Tmux sessions work smoothly, one must change the Tmux key either locally or remotely. I think there might also be another way around this (without reconfiguring the prefix key), but that is pretty cumbersome to use as far as I remember. To change the prefix key from the standard `b` to, for example, `g`, you must add this to the `tmux.conf`:
+To make nested Tmux sessions work smoothly, one must change the Tmux key locally or remotely. There might also be another way around this (without reconfiguring the prefix key), but that is cumbersome, as far as I remember. To change the prefix key from the standard `b` to, for example, `g`, you must add this to the `tmux.conf`:
```
set-option -g prefix C-g
@@ -144,7 +144,7 @@ In my case, I have that deployed to all remote servers through a configuration m
## 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 search for session names comes in handy, as I often don't remember the exact session names.
+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.
```bash
tmux::search () {
@@ -160,7 +160,7 @@ alias ts=tmux::search
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).
-For this to work, you will need to install the `fzf` command on your computer.
+You must install the `fzf` command on your computer for this to work.
## The `tssh` alias - Cluster SSH replacement
@@ -168,10 +168,10 @@ Before I used Tmux, I was a heavy user of ClusterSSH, which allowed me to log in
=> https://github.com/duncs/clusterssh
-But 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 actually spawned terminal windows. The `tmux::cluster_ssh` function can have N arguments, where:
+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. The `tmux::cluster_ssh` function can have N arguments, where:
-* ...the first argument will be the session name (see `tmux::tssh_from_argument` helper function) and all remaining arguments will be server hostnames/FQDNs to connect to simultaneously.
-* ...or, the first argument is a file name and the file contains a list of hostnames/FQDNs (see `tmux::ssh_from_file` helper function)
+* ...the first argument will be the session name (see `tmux::tssh_from_argument` helper function), and all remaining arguments will be server hostnames/FQDNs to connect to simultaneously.
+* ...or, the first argument is a file name, and the file contains a list of hostnames/FQDNs (see `tmux::ssh_from_file` helper function)
This is how it looks:
@@ -187,11 +187,11 @@ tmux::cluster_ssh () {
alias tssh=tmux::cluster_ssh
```
-This function is really 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.
+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 liket his:
+This is the most magic helper function we will cover in this post. It looks like this:
```bash
tmux::tssh_from_argument () {
@@ -213,9 +213,9 @@ tmux::tssh_from_argument () {
}
```
-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 connect to. The first one is used to create the initial session. All remaining ones are then 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 enabling the neat ClusterSSH feature to run commands on multiple servers at once. Once done, we attach (or switch, if we are already in Tmux) to it.
+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`:
+Sometimes, I don't want the synchronized panes behaviour 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`:
```
@@ -225,7 +225,7 @@ bind-key P setw synchronize-panes on
### The `tmux::tssh_from_file` helper
-This one simply 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 enabling me to open clustered SSH sessions from an input file as well.
+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.
```bash
tmux::tssh_from_file () {
@@ -238,11 +238,11 @@ tmux::tssh_from_file () {
## Copy and paste workflow
-As you will see a bit later in this blog post, I have configured a history limit of 1 million items in Tmux, so 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).
+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).
-How this works is I press `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.
+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.
-Most often, I am searching the history backward with `prefix-key [` followed by a `?`, which opens the search prompt.
+I often search the history backwards with `prefix-key [` followed by a `?`, which opens the 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, 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).
@@ -250,8 +250,7 @@ Once the text is yanked, I switch to another Tmux window or session where, for e
## Tmux configurations
-There are some features I have configured directly in Tmux that don't require an external shell alias to function properly. Let's walk line by line through my local `~/config/tmux/tmux.conf`:
-
+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
@@ -265,13 +264,13 @@ set-window-option -g mode-keys vi
```
-There's not much magic happening here just yet. 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.
+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 a lot of terminal output, which I also like to search within Tmux, so I add a large enough `history-limit`, enabling me to search backward in Tmux for any output up to a million lines of text.
+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 colors (personal taste), I also set `escape-time` to `0`, which is just a workaround, as otherwise my Helix text editor's `ESC` key would take ages to trigger within Tmux. I don't remember the gory details. You can leave it out, and if everything works fine for you, then just leave it out.
+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.
-I am navigating within Tmux using Vi key-bindings, so the `mode-keys` is set to `vi`. I am a user of the Helix modal text editor, and it is close enough to vi bindings for simple navigation in order to feel "native" to me. (BTW, I have been a long time Vim and NeoVim user, but I switched eventually to Helix - It's off-topic for here, but maybe worh another blog post one time).
+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 next set of lines in the configuration file are:
@@ -297,7 +296,7 @@ bind-key F new-window -n "session-switcher" "tmux list-sessions | fzf | cut -d:
bind-key T choose-tree
```
-The first one makes is to, that any new window starts in the current directory. The second one is a bit more interesting. I lists all open sessions in the fuzzy finder. I rely heavily on this during my daily workflow for switching between various sessions depending on my task at hand. E.g. from a remote cluster SSH session to a local code editor. The third one `choose-tree` simply opens a tree view in Tmux listing all sessions and windows and panes. This one is pretty handy to get a better overview of what is currently running in any of the local Tmux sessions.
+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, windows, and panes. This one is handy to overview better what is currently running in any local Tmux sessions.
The last remaining lines in my configuration file are:
@@ -307,6 +306,6 @@ 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 (all remote SSH sessions) receive the same keystrokes. It 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.
+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 simply reloads my Tmux configuratin on the fly.
+The last one reloads my Tmux configuration on the fly.