#!/bin/sh # plumb -- plumber for tmux's copy-pipe # reads the item to plumb from stdin, optionally takes a working dir # 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 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 '{ sub("^~", ENVIRON["HOME"], $1); print $1 }') case "$ITEM" in http*) xdg-open "$ITEM" ;; [a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*) \ tmuxdo "git show $ITEM 2>&1 | less" ;; [a-zA-Z0-9._-]*:[0-9]*:*) tmuxdo "fned \"$ITEM\"" ;; [a-zA-Z0-9._-]*\([1-9]\)) PAGE=${ITEM%%\([1-9]\)} tmuxdo "man \"$PAGE\"" ;; *) if [ -d "$ITEM" ]; then tmuxdo "cd $ITEM && $SHELL" elif [ -e "$ITEM" ]; then tmuxdo "${EDITOR:-vi} $ITEM" fi ;; esac