dotfiles

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

commit 9fcb3eb9c04463382fb66fc106e14511cdeb3d35 (patch)
parent 04e0d234d6e2b3db4ae6a7230396c49e1b9fee58
Author: Alex Karle <alex@alexkarle.com>
Date:   Sat, 26 Feb 2022 00:14:11 -0500

tmux: Add support for git-grep under cursor

I do this _all_ the time in vim, so it's super cool to think I
can use tmux + plumb to achieve effectively the same but with any
unstructured text.

As I write this though, I'm realizing that an mless(1) style gless(1)
which has all the rows of git-grep and knows how to feed them to
vim based on custom keybindings and exit codes might be cool.. hm.
Like a git-gui using less :thinking:

Diffstat:
M.tmux.conf | 8+++++++-
Mbin/plumb | 8+++++---
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/.tmux.conf b/.tmux.conf @@ -10,8 +10,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 +# plumber! `a` in copy-mode sends to the 'plumb' command (A splits above) bind-key -T copy-mode-vi a send-keys -X copy-pipe-no-clear "plumb #{pane_current_path}" +bind-key -T copy-mode-vi A send-keys -X copy-pipe-no-clear "plumb #{pane_current_path} -b" # Less delay on pressing escape (for vim) set-option -sg escape-time 10 @@ -32,6 +33,11 @@ bind-key S copy-mode \; send-keys -X search-backward "[a-f0-9]{6,40}" bind-key F copy-mode \; send-keys -X search-backward "^[^ :@#]*:[0-9]*:.*" bind-key P copy-mode \; send-keys -X search-backward "[^ :@#]*/[^:@# ]*" +# bind G into git-grep word under cursor (use with F above) +bind-key G copy-mode \; send-keys -X select-word \; \ + send-keys -X copy-pipe-and-cancel "xclip" \; \ + split-window -c "#{pane_current_path}" -l 10 sh -c 'git grep -n "$(xclip -o)" 2>&1 | less' + # Use | and - for more intuitive splits (in the same location!) bind-key | split-window -c "#{pane_current_path}" -h bind-key - split-window -c "#{pane_current_path}" -v diff --git a/bin/plumb b/bin/plumb @@ -1,11 +1,13 @@ #!/bin/sh # plumb -- plumber for tmux's copy-pipe # reads the item to plumb from stdin, optionally takes a working dir +# and arguments for split-window (i.e. to split above or set size) read ITEM if [ -n "$1" ]; then cd "$1" fi +shift # only accept first argument (by whitespace) ITEM=$(echo "$ITEM" | awk '{ print $1 }') @@ -13,7 +15,7 @@ ITEM=$(echo "$ITEM" | awk '{ print $1 }') 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" ;; + 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