Last active
July 25, 2024 11:53
-
-
Save wsgac/e495b550b23d9b96ecc1bf434ffa45cc to your computer and use it in GitHub Desktop.
Attempt to emulate Emacs registers in Tmux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- conf -*- | |
# Initialize alphanumerical registers to avoid the problem with 'delete-buffer' | |
run "tmux set-buffer -b a \"$(echo ' ')\"" | |
run "tmux set-buffer -b b \"$(echo ' ')\"" | |
run "tmux set-buffer -b c \"$(echo ' ')\"" | |
run "tmux set-buffer -b d \"$(echo ' ')\"" | |
run "tmux set-buffer -b e \"$(echo ' ')\"" | |
run "tmux set-buffer -b f \"$(echo ' ')\"" | |
run "tmux set-buffer -b g \"$(echo ' ')\"" | |
run "tmux set-buffer -b h \"$(echo ' ')\"" | |
run "tmux set-buffer -b i \"$(echo ' ')\"" | |
run "tmux set-buffer -b j \"$(echo ' ')\"" | |
run "tmux set-buffer -b k \"$(echo ' ')\"" | |
run "tmux set-buffer -b l \"$(echo ' ')\"" | |
run "tmux set-buffer -b m \"$(echo ' ')\"" | |
run "tmux set-buffer -b n \"$(echo ' ')\"" | |
run "tmux set-buffer -b o \"$(echo ' ')\"" | |
run "tmux set-buffer -b p \"$(echo ' ')\"" | |
run "tmux set-buffer -b q \"$(echo ' ')\"" | |
run "tmux set-buffer -b r \"$(echo ' ')\"" | |
run "tmux set-buffer -b s \"$(echo ' ')\"" | |
run "tmux set-buffer -b t \"$(echo ' ')\"" | |
run "tmux set-buffer -b u \"$(echo ' ')\"" | |
run "tmux set-buffer -b v \"$(echo ' ')\"" | |
run "tmux set-buffer -b w \"$(echo ' ')\"" | |
run "tmux set-buffer -b x \"$(echo ' ')\"" | |
run "tmux set-buffer -b y \"$(echo ' ')\"" | |
run "tmux set-buffer -b z \"$(echo ' ')\"" | |
# Copy to user-selected register | |
bind -T copy-mode r command-prompt -1 -p '(register)' 'delete-buffer -b %1 ; send -X copy-pipe "tmux set-buffer -n %1"' | |
# Paste from user-selected register | |
bind -T prefix C-] command-prompt -1 -p '(register)' 'paste-buffer -b %1' | |
# Split window inheriting $PWD from current pane | |
# Bind intuitive, yet unused keybindings | |
bind -T prefix | split-window -h -c "#{pane_current_path}" | |
bind -T prefix - split-window -c "#{pane_current_path}" |
I've opted for a not-too-pretty-but-effective solution of pre-initializing a certain number of buffers (in my case, a
to z
) so that delete-buffer
always has something to operate on.
I've added bindings for variants of the split commands that inherit $PWD
from the current pane. It can be useful e.g. when opening multiple logs stored in some non-trivial directory hierarchy - saves repeated cd
-ing to those directories. I picked intuitive keybindings: |
makes a horizontal split and -
- vertical.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an attempted solution of the problem, combining Tmux' notion of paste buffers. The first command (bound to
r
incopy-mode
) prompts the user for a single character buffer name and then pipes the selection to that buffer (usingset-buffer
invoked via shell). The second command (bound to<prefix> C-]
) simply prompts for the buffer and pastes its content. The current limitation shows when the user wants to overwrite an existing buffer. Instead, a new buffer gets created.