~akarle/dotfiles

dotfiles/bin/plumb -rwxr-xr-x 1.1 KiB
d2fe3c35Alex Karle bin: Add no9 function to strip plan9 from PATH 13 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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