commit 4c3b21f0ba96fcce188f8c55599a4ec8a98a13fe
parent ab3ca5e2bf3317933b7bec8d10f92cd4a5686991
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 17 May 2026 20:46:55 +0200
New blog post
Diffstat:
3 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/src/blog/2024-07-11-tmux-battery/tmux-battery.md b/src/blog/2024-07-11-tmux-battery/tmux-battery.md
@@ -1,4 +1,6 @@
-# tmux tricks #1: battery status indicator
+# tmux trick #1: battery status indicator
+
+*This post is part of a [series](../../series)*
[tmux](https://github.com/tmux/tmux/wiki) is a program that allows
you to create multiple virtual terminals in the same shell and keep
@@ -162,3 +164,5 @@ is created. The `-g` is used to apply this command globally. My
understanding of this is still superficial, but for now I am happy
that the battery status is there. Maybe I'll learn about sessions
at some point, and I'll write a new blog post about them :)
+
+*Next in the series: [copy to clipboard](../2026-05-17-tmux-clipboard)*
diff --git a/src/blog/2026-05-17-tmux-clipboard/tmux-clipboard.md b/src/blog/2026-05-17-tmux-clipboard/tmux-clipboard.md
@@ -0,0 +1,56 @@
+# tmux trick #2: copy to clipboard
+
+*This post is part of a [series](../../series)*
+
+Recently, for reasons that I may explain in a future blog post, I went
+through some old configuration files of mine, and I found something in
+my `.tmux.conf` that I thought would be worth a second post in this
+series - only 2 years after the first episode, not bad!
+
+## Copy mode
+
+[tmux](https://en.wikipedia.org/wiki/Tmux) has a feature called *copy mode*
+that allows one to visually select and copy text, all via your keyboard.
+By default you can enter copy mode by pressing `C-b [` (`Ctrl+B` followed
+by `[`); from there you can navigate the text that is currently on your
+terminal with arrow keys and [Emacs](https://en.wikipedia.org/wiki/Emacs)-style
+key bindings - or with hjkl and other
+[Vim](https://en.wikipedia.org/wiki/Vim_(text_editor))-style bindings if
+you have a `VISUAL` or `EDITOR` [environment
+variable](https://en.wikipedia.org/wiki/Environment_variable) set to `vi`.
+
+You can then start selecting text by pressing `Space`, and confirm the
+selection by pressing `Enter`. The selection will then be copied to
+an internal tmux buffer, and you can paste it by pressing `C-b ]`.
+
+Actually, tmux offers multiple copy-buffers, but honestly I have never
+used this feature. You can read more about this in its [manual
+page](https://man.openbsd.org/tmux).
+
+## Copy to clipboard
+
+By default, tmux will copy the selection to its internal buffer, but you
+may want to paste that text somewhere outside of tmux - maybe in a chat
+application or in a web browser URL bar. And here is the trick: you can
+actually tell tmux to [pipe](https://en.wikipedia.org/wiki/Pipeline_(Unix))
+the selection to a custom command. For example, if you have this in your
+`.tmux.conf`:
+
+```
+set -s copy-command "xsel -ib"
+```
+
+tmux will not only copy the selection to its internal buffer, but also
+send it to the `xsel -ib` command. In case you did not know,
+[`xsel`](https://linux.die.net/man/1/xsel)
+is a command that copies its standard input to the X session
+[clipboard](https://en.wikipedia.org/wiki/Clipboard_(computing));
+this way you will be able to paste the copied text into any other
+graphical application with the usual `Ctrl+V`. Neat!
+
+## tmux show-buffer
+
+Here one last trick: with the `tmux show-buffer` command you can print the
+current tmux selection to standard output. You can use this in shell scripts,
+for example, or in more complex tmux key bindings in your configuration file.
+And that's a teaser for the next tmux trick :)
diff --git a/src/series/series.md b/src/series/series.md
@@ -51,12 +51,12 @@ My adventures in learning C++ as a C programmer.
* Episode 2: [RAII](../blog/2024-12-26-taming-cpp-raii)
* Episode 3: [templates, constraints and concepts](../blog/2025-01-21-taming-cpp-templates)
-## Learning Rust
+## tmux tricks
-I have recently started learning Rust, documenting the process in a
-small series of blog posts. These posts are all marked by the crab emoji
-'🦀', which is something of a meme in the Rust community, as far as
-I understand.
+Some tips and tricks for using [tmux](https://en.wikipedia.org/wiki/Tmux),
+the terminal multiplexer. In these posts I try to focus on one practical
+aspect of this application at the time, without going too in depth into
+the inner workings of tmux.
-* [Cargo culture shock](../blog/2025-06-13-cargo-culture-shock)
-* [Stunned by the borrow checker](../blog/2025-06-26-borrow-checker)
+* Trick #1: [battery status indicator](../blog/2024-07-11-tmux-battery)
+* Trick #2: [copy to clipboard](../blog/2026-05-17-tmux-clipboard)