← xoc3.io

2021-08-06 - tmux capture pane

something i've found myself doing a lot is running a command twice, just so i can edit the text a second time. another thing i found myself doing a lot is using my mouse to copy a url or file from the screen. luckily, i'm always in a tmux session and tmux has a cool `capture-pane` command, so i used that to my advantage and came up with some cool solutions.

my first solution solves the problem of navigating/editing the output of a previously run command. i'm aware of tmux's copy mode ("prefix+["), but the copy mode has a limited set of vim keybindings so it's not very pleasant to use. anytime someone tries to reimplement vim bindings, i get the feeling they should just allow someone to use their editor. so instead of opening copy mode, i created a kakoune mode for tmux. just copy this into your tmux.conf:

the `-eJS -` part of capture-pane joins lines that go off the screen, uses all of the history instead of only the viewable screen, and keeps color codes. i want to keep color codes, because i'm using a great kakoune plugin:

kak-ansi by eraserhd

to solve the second problem, i created a shell script:

that command is kind of like ls, but instead if listing files, it lists all words on the screen. i'm also removing ":"s from the end of words, because i don't find it helpful. combining the command with fzf in a zsh keybinding makes all the difference:

now alt-z will use fuzzy filtering to insert text. using this with my clipboard tool makes copying words from the screen to the clipboard without a mouse very easy:

of course, there are plenty of improvements i can make to this process. what i've shown in this past is a good start. my latest improvements to this process can always be found in my dotfiles:

my dotfiles