dotfiles

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

tmux-plumb (1101B) [raw]


      1 #!/bin/sh
      2 # plumb -- plumber for tmux's copy-pipe
      3 # reads the item to plumb from stdin, optionally takes a working dir
      4 # most items open in a new tmux split, or new window if -w given
      5 args=$(getopt w $*)
      6 if [ "$?" != "0" ]; then
      7 	echo "usage: plumb [-w] [directory]" 1>&2
      8 	exit 1
      9 fi
     10 
     11 set -- $args
     12 while [ "$#" != "0" ]; do
     13 	case "$1" in
     14 		-w) NEW_WINDOW=1 ; shift ;;
     15 		--) shift ; break ;;
     16 	esac
     17 done
     18 
     19 if [ -n "$1" ]; then
     20 	cd "$1"
     21 	shift
     22 fi
     23 
     24 tmuxdo() {
     25 	if [ "$NEW_WINDOW" = "1" ]; then
     26 		tmux new-window sh -c "$1"
     27 	else
     28 		tmux split-window sh -c "$1"
     29 	fi
     30 }
     31 
     32 # only accept first argument (by whitespace)
     33 read ITEM
     34 ITEM=$(echo "$ITEM" | awk '{ sub("^~", ENVIRON["HOME"], $1); print $1 }')
     35 
     36 case "$ITEM" in
     37 	http*) xdg-open "$ITEM" ;;
     38 	[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*) \
     39 		tmuxdo "git show $ITEM 2>&1 | less" ;;
     40 	[a-zA-Z0-9._-]*:[0-9]*:*) tmuxdo "fned \"$ITEM\"" ;;
     41 	[a-zA-Z0-9._-]*\([1-9]\))
     42 		PAGE=${ITEM%%\([1-9]\)}
     43 		tmuxdo "man \"$PAGE\"" ;;
     44 	*)
     45 		if [ -d "$ITEM" ]; then
     46 			tmuxdo "cd $ITEM && $SHELL"
     47 		elif [ -e "$ITEM" ]; then
     48 			tmuxdo "${EDITOR:-vi} $ITEM"
     49 		fi
     50 		;;
     51 esac