dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | README | LICENSE

commit 8b0b78c80ae8fc98f1b6d049c20a9de0460a92f8 (patch)
parent 9bc1efd68cc9e4c3b95f632dd589229fd9bfa8fb
Author: Alex Karle <alex@alexkarle.com>
Date:   Mon, 21 Feb 2022 01:03:16 -0500

tmux: Add plumb command and key-binding

Inspired by acme(1), I really wanted a way to take the
tmux selection contents and open them in the appropriate
application.

I spent a while exploring st(1)'s patch for this, but I didn't
really want to use the vte.sh pre-prompt updating of a cwd
and the "simple" patch only supports execution from st's cwd,
which breaks down if tmux is in use.

And while I was figuring this all out, I realized I could just
hijack tmux's copy-pipe command and do it here!

This is a first take and I expect to iterate a bit, but it's
already quite cool :)

Diffstat:
M.tmux.conf | 3+++
Abin/plumb | 21+++++++++++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/.tmux.conf b/.tmux.conf @@ -8,6 +8,9 @@ set-option -g prefix C-a unbind-key C-b bind-key C-a send-prefix +# plumber! `a` in copy-mode sends to the 'plumb' command +bind-key -T copy-mode-vi a send-keys -X copy-pipe-and-cancel "plumb #{pane_current_path}" + # Less delay on pressing escape (for vim) set-option -sg escape-time 10 diff --git a/bin/plumb b/bin/plumb @@ -0,0 +1,21 @@ +#!/bin/sh +# plumb -- plumber for tmux's copy-pipe +# reads the item to plumb from stdin, optionally takes a working dir +IFS=' +' +read ITEM + +if [ -n "$1" ]; then + cd "$1" +fi + +# trim whitespace off the ITEM +ITEM=$(echo "$ITEM" | xargs) + +case "$ITEM" in + http*) firefox "$ITEM" ;; + [a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*) \ + tmux split-window sh -c "git show $ITEM 2>&1 | less" ;; + [a-zA-Z0-9.]*:[0-9]*:*) tmux split-window sh -c "fned \"$ITEM\"" ;; + *) tmux split-window sh -c "vi $ITEM" ;; +esac