dotfiles

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

commit 020ccaaa9321324ecde0189d027d985112a76195 (patch)
parent f6c940d1a84832f7d604a0fd326cec5bb510f61e
Author: Alex Karle <alex@alexkarle.com>
Date:   Sat, 26 Feb 2022 00:51:35 -0500

plumb: Add plumb -w option to open in new window

And of course update tmux to use it!

I found that a lot of the time, more than 2 vertical splits
is already cluttered. Since these windows close on their own
when vi/less dies, it's nice to just pop them in their own
window to get the full real-estate.

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

diff --git a/.tmux.conf b/.tmux.conf @@ -12,7 +12,7 @@ bind-key C-a send-prefix # 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" +bind-key -T copy-mode-vi A send-keys -X copy-pipe-no-clear "plumb -w #{pane_current_path}" # Less delay on pressing escape (for vim) set-option -sg escape-time 10 diff --git a/bin/plumb b/bin/plumb @@ -1,21 +1,42 @@ #!/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 +# most items open in a new tmux split, or new window if -w given +args=$(getopt w $*) +if [ "$?" != "0" ]; then + echo "usage: plumb [-w] [directory]" 1>&2 + exit 1 +fi + +set -- $args +while [ "$#" != "0" ]; do + case "$1" in + -w) NEW_WINDOW=1 ; shift ;; + --) shift ; break ;; + esac +done if [ -n "$1" ]; then cd "$1" + shift fi -shift + +tmuxdo() { + if [ "$NEW_WINDOW" = "1" ]; then + tmux new-window sh -c "$1" + else + tmux split-window sh -c "$1" + fi +} # only accept first argument (by whitespace) +read ITEM ITEM=$(echo "$ITEM" | awk '{ print $1 }') case "$ITEM" in - http*) firefox "$ITEM" ;; + http*) xdg-open "$ITEM" ;; [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" ;; + tmuxdo "git show $ITEM 2>&1 | less" ;; + [a-zA-Z0-9.]*:[0-9]*:*) tmuxdo "fned \"$ITEM\"" ;; + *) tmuxdo "vi $ITEM" ;; esac