commit d87c22be1700e064d15b0cd1de19a3c65d376261
parent 4c3b21f0ba96fcce188f8c55599a4ec8a98a13fe
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 28 Jun 2026 09:35:39 +0200
New blog post
Diffstat:
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/src/blog/2026-05-17-tmux-clipboard/tmux-clipboard.md b/src/blog/2026-05-17-tmux-clipboard/tmux-clipboard.md
@@ -54,3 +54,5 @@ 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 :)
+
+*Next in the series: [open URLs without the mouse](../2026-06-28-tmux-open-urls)*
diff --git a/src/blog/2026-06-28-tmux-open-urls/tmux-open-urls.md b/src/blog/2026-06-28-tmux-open-urls/tmux-open-urls.md
@@ -0,0 +1,54 @@
+# tmux trick #3: open URLs without the mouse
+
+*This post is part of a [series](../../series)*
+
+My [last post in this series](../2026-05-17-tmux-clipboard) on copy mode
+was inspired by an old `.tmux.conf` file that I found in a backup folder.
+In that same file I also had a command that selects all URLs that are
+visible in the current pane, shows them to the user in a
+[dmenu](https://tools.suckless.org/dmenu) session, and opens the
+selected URL in a browser. This command is bound to `C-b u` with
+the following configuration line:
+
+```
+bind u run "tmux capture-pane; tmux show-buffer | urlgrep | dmenu -l | xargs firefox"
+```
+
+This command is a great example of UNIX program composability. Let's break it down!
+
+## The pipeline
+
+First, `tmux capture-pane` copies all the text of the current pane in
+its copy buffer. Then `tmux show-buffer` prints the current copy buffer
+to standard output - we talked about this last time.
+
+This text is then [piped](https://en.wikipedia.org/wiki/Pipeline_(Unix))
+into `urlgrep`, a custom script that I wrote by copy-pasting a regular
+expression from some StackOverflow answer:
+
+```
+#!/bin/sh
+
+protocols='http|https|ftp|sftp|gemini|mailto'
+valid_chars="][a-zA-Z0-9_~/?#@!$&'()*+=.,;:-"
+regex="(($protocols):|www\.)[$valid_chars]+"
+
+egrep -o "$regex"
+```
+
+This [grep](../2023-08-20-grep) command selects all URLs from its standard
+input and prints them out one per line. These URLs are then sent to dmenu,
+a graphical tool that prompts the user to select one of the items it received
+in its standard input. The `-l` option is used to change `dmenu`'s layout so
+that it shows one option per line.
+
+The user's selection is then printed by `dmenu` to standard output; so we
+use `xargs` to convert it to an argument for the `firefox` command. And
+that's it! You can now follow links from your terminal using only your keyboard.
+
+## Caveats
+
+If a URL is broken into multiple lines, my `urlgrep` script is only going to
+select it until the end of the first line, so you won't be able to open
+it correctly with this configuration. However, I found this to be a common
+issue in many terminal emulators.
diff --git a/src/series/series.md b/src/series/series.md
@@ -60,3 +60,4 @@ the inner workings of tmux.
* Trick #1: [battery status indicator](../blog/2024-07-11-tmux-battery)
* Trick #2: [copy to clipboard](../blog/2026-05-17-tmux-clipboard)
+* Trick #3: [open URLs without the mouse](../blog/2026-06-28-tmux-open-urls)