ITERM2 SMART SELECTION FOR TMUX, GOPHER, AND BEYOND Preamble ---------------------------------------------------------------------- I am a reluctant Mac OS user. Against my better judgement---but owing to the encouragement of a friend---I purchased a used Macbook Air M2 in the winter. My experience has so far been both wonderful and woeful. I love being able to haul this tiny thing around the house, or to stick it in my bag and use it on break at work. Previously, my computing was desk bound. Now I'm assuming all sorts of contorted positions while chatting on IRC, burrowing through gopherspace, and developing baby programming projects. I like these new positions of computing. The informality of it all has made me less precious about my computer time. Likewise, it has made computing pervade more of my life. My thinking and entertaining tools are now closer to me at all times. I like that feeling. I hate the Mac OS user interface. There's all sorts of weird keys, gestures, and window manager shenanigans that make navigating apps and settings an often disorienting experience. I have found it impossible to hold a mental model of my workspace at a given moment. All I know is that things are open, somewhere. To find a given application I sometimes have to try multiple desktop arrangements, either cycling windows, or showing the desktop overview, or checking stage manager. It's awful, actually. To cope I embrace the disorientation. Everything about the Mac OS user interface is so clicky, too. Like, I'm constantly clicking menus, buttons, window title bars, and text to get things done. I strongly prefer the keyboard centric lifestyle of an i3 window manager. Can I nuke the native experience of Mac OS? I don't know. I hope so. Slowly, I am finding little refuges from these horrors. iTerm2, maybe, will be such a place of peace and tranquility. iTerm2 smart selection ---------------------------------------------------------------------- I spend a lot of time on IRC. I value the camaraderie, the ideas, the jokes, and the general sense of belonging my servers provide. A good IRC channel is like a hearth---it radiates comfort and security. The quality of my access to IRC is not something I will compromise. On IRC, It's common for people to post links to content: videos, music, articles, images, repositories, and so on. I like to be able to open these items effortlessly. These things aren't generally that important, but there's usually some value to derive from out-of-band content. The worst way to open links is to retype them by hand. Second worst would be to manually select and copy the region. Hilariously, I did both of those on my Mac until I learned about iTerm2. iTerm2 has a smart selection feature. From what I can tell, it's similar to the rxvt match and select functionality. It's worse, for sure, because I can't invoke the feature with a keystroke. (I'm in the land of giant track pads and pointy devices---go figure). Aside from that limitation, it seems to be doing what I need. Namely, opening URIs for different protocols and passing them to a chosen program. Below I detail the smart selection rule and command combo for gopher. It's really not that complicated, but somehow it still took me an evening to figure out. Because the whole thing feels so stupid I wrote this phlog post about it, too :') Tmux/Gopher smart selection rule and action ---------------------------------------------------------------------- Below are the regex and action. The rule was obviously adapted from the app's existing rule for HTTP. The action was a bit trickier. I invoke `tmux' and its `send-keys' command. A new pane is created, then the URI is edited remove gophers (if necessary), then lynx is invoked with the URI. Regex: `((?<!\()gopher+s?://([a-z0-9A-Z]+(:[a-zA-Z0-9]+)?@)?([a-z0-9A-Z][-a-z0-9A-Z]*\.)*[A-Za-z][-A-Za-z]*((:[0-9]+)?)(/[a-zA-Z0-9;/.\-_+%?&@=#~()]*)?)|(https?://([a-z0-9A-Z]+(:[a-zA-Z0-9]+)?@)?([a-z0-9A-Z][-a-z0-9A-Z]*\.)*[A-Za-z][-A-Za-z]*((:[0-9]+)?)(/[a-zA-Z0-9;/.\-_+%?&@=#~(]*)?)' Action: Run command, `/opt/local/bin/tmux send-keys -t "$pane" C-c C-z 'lynx $( echo \0 | sed "s/gophers/gopher/")' Enter' Beyond ...................................................................... Well, there's no beyond yet. But I'm pretty sure I'll be adding more rules and actions in the future. When I do, I'll add those here.