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