aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blog/2026-05-17-tmux-clipboard/tmux-clipboard.md2
-rw-r--r--src/blog/2026-06-28-tmux-open-urls/tmux-open-urls.md54
-rw-r--r--src/series/series.md1
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
index f1721fe..deac3d6 100644
--- 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
54current tmux selection to standard output. You can use this in shell scripts, 54current tmux selection to standard output. You can use this in shell scripts,
55for example, or in more complex tmux key bindings in your configuration file. 55for example, or in more complex tmux key bindings in your configuration file.
56And that's a teaser for the next tmux trick :) 56And that's a teaser for the next tmux trick :)
57
58*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
new file mode 100644
index 0000000..aaaf3a6
--- /dev/null
+++ b/src/blog/2026-06-28-tmux-open-urls/tmux-open-urls.md
@@ -0,0 +1,54 @@
1# tmux trick #3: open URLs without the mouse
2
3*This post is part of a [series](../../series)*
4
5My [last post in this series](../2026-05-17-tmux-clipboard) on copy mode
6was inspired by an old `.tmux.conf` file that I found in a backup folder.
7In that same file I also had a command that selects all URLs that are
8visible in the current pane, shows them to the user in a
9[dmenu](https://tools.suckless.org/dmenu) session, and opens the
10selected URL in a browser. This command is bound to `C-b u` with
11the following configuration line:
12
13```
14bind u run "tmux capture-pane; tmux show-buffer | urlgrep | dmenu -l | xargs firefox"
15```
16
17This command is a great example of UNIX program composability. Let's break it down!
18
19## The pipeline
20
21First, `tmux capture-pane` copies all the text of the current pane in
22its copy buffer. Then `tmux show-buffer` prints the current copy buffer
23to standard output - we talked about this last time.
24
25This text is then [piped](https://en.wikipedia.org/wiki/Pipeline_(Unix))
26into `urlgrep`, a custom script that I wrote by copy-pasting a regular
27expression from some StackOverflow answer:
28
29```
30#!/bin/sh
31
32protocols='http|https|ftp|sftp|gemini|mailto'
33valid_chars="][a-zA-Z0-9_~/?#@!$&'()*+=.,;:-"
34regex="(($protocols):|www\.)[$valid_chars]+"
35
36egrep -o "$regex"
37```
38
39This [grep](../2023-08-20-grep) command selects all URLs from its standard
40input and prints them out one per line. These URLs are then sent to dmenu,
41a graphical tool that prompts the user to select one of the items it received
42in its standard input. The `-l` option is used to change `dmenu`'s layout so
43that it shows one option per line.
44
45The user's selection is then printed by `dmenu` to standard output; so we
46use `xargs` to convert it to an argument for the `firefox` command. And
47that's it! You can now follow links from your terminal using only your keyboard.
48
49## Caveats
50
51If a URL is broken into multiple lines, my `urlgrep` script is only going to
52select it until the end of the first line, so you won't be able to open
53it correctly with this configuration. However, I found this to be a common
54issue in many terminal emulators.
diff --git a/src/series/series.md b/src/series/series.md
index 2194d90..92fb7a9 100644
--- a/src/series/series.md
+++ b/src/series/series.md
@@ -60,3 +60,4 @@ the inner workings of tmux.
60 60
61* Trick #1: [battery status indicator](../blog/2024-07-11-tmux-battery) 61* Trick #1: [battery status indicator](../blog/2024-07-11-tmux-battery)
62* Trick #2: [copy to clipboard](../blog/2026-05-17-tmux-clipboard) 62* Trick #2: [copy to clipboard](../blog/2026-05-17-tmux-clipboard)
63* Trick #3: [open URLs without the mouse](../blog/2026-06-28-tmux-open-urls)

Generated with cgit - Back to sebastiano.tronto.net