blob: 977d2d57cbf4806ca35aec93df0b29287e7380aa (
plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/bin/sh
# My interpretation of a plumber (plan9 style).
# It scans the selected text (xsel) and decides what to do with it among
# some possibilities (open file, open url, man page...). If none is matched,
# a choice is prompted.
# Requires: dmenu (or similar), mail-compose, open-file, websearch, xsel
# TODO:
# send mail to email address;
# calendar if it is a date
# choice: pipe to another program
browser=${BROWSER:-firefox}
terminal=${TERMINAL:-xterm}
xeditor=${XEDITOR:-gedit}
menu=${MENU:-dmenu}
menuopts="-l 10"
text=$(xsel | sed 's/\n/ /g')
if [ $(echo "$text" | wc -c) -ge 11 ]; then
shorttext=$(echo "$text" | cut -b 1-10)...
else
shorttext="$text"
fi
choice() {
chosen=$(printf "websearch\nedit" | \
$menu $menuopts -p "What to do with \"$shorttext\"?")
if [ "$chosen" = "websearch" ]; then
websearch $text
elif [ "$chosen" = "edit" ]; then
f=$(mktemp)
xsel > "$f"
$xeditor "$f"
fi
}
trymail() {
addr=$(echo "$1" | addressgrep)
( [ -n "$addr" ] && mail-compose $addr ) || return 1
}
tryman() {
number=$(echo "$1" | sed 's/[^1-8]//g')
name=$(echo "$1" | sed 's/([1-8])//g' | sed 's/ //g')
if [ $(man -w "$number" "$name" | wc -l) = 1 ]; then
$terminal -e man "$number" "$name"
return 0
else
return 1
fi
}
tryurl() {
url=$(echo "$1" | urlgrep)
( [ -n "$url" ] && $browser $url ) || return 1
}
open-file "$text" || \
tryurl "$text" || \
trymail "$text" || \
tryman "$text" || \
choice
|