aboutsummaryrefslogtreecommitdiff
path: root/unused/xplumb
diff options
context:
space:
mode:
Diffstat (limited to 'unused/xplumb')
-rwxr-xr-xunused/xplumb65
1 files changed, 65 insertions, 0 deletions
diff --git a/unused/xplumb b/unused/xplumb
new file mode 100755
index 0000000..1d89796
--- /dev/null
+++ b/unused/xplumb
@@ -0,0 +1,65 @@
1#!/bin/sh
2
3# My interpretation of a plumber (plan9 style).
4# It scans the selected text (xsel) and decides what to do with it among
5# some possibilities (open file, open url, man page...). If none is matched,
6# a choice is prompted.
7
8# Requires: dmenu (or similar), mail-compose, open-file, terminal, websearch,
9# xedit, xsel
10
11# TODO:
12# send mail to email address;
13# calendar if it is a date
14# choice: pipe to another program
15
16browser=${BROWSER:-firefox}
17menu=${MENU:-dmenu}
18menuopts="-l 10"
19
20text=$(xsel | sed 's/\n/ /g')
21if [ "${#text}" -ge 11 ]; then
22 shorttext=$(echo "$text" | cut -b 1-10)...
23else
24 shorttext="$text"
25fi
26
27choice() {
28 chosen=$(printf "websearch\nedit" | \
29 $menu $menuopts -p "What to do with \"$shorttext\"?")
30
31 if [ "$chosen" = "websearch" ]; then
32 websearch "$text"
33 elif [ "$chosen" = "edit" ]; then
34 f=$(mktemp)
35 xsel > "$f"
36 xedit "$f"
37 fi
38}
39
40trymail() {
41 addr=$(echo "$1" | addressgrep)
42 ( [ -n "$addr" ] && mail-compose "$addr" ) || return 1
43}
44
45tryman() {
46 number=$(echo "$1" | sed 's/[^1-8]//g')
47 name=$(echo "$1" | sed 's/([1-8])//g' | sed 's/ //g')
48 if [ "$(man -w "$number" "$name" | wc -l)" = 1 ]; then
49 terminal -e man "$number" "$name"
50 return 0
51 else
52 return 1
53 fi
54}
55
56tryurl() {
57 url=$(echo "$1" | urlgrep)
58 ( [ -n "$url" ] && "$browser" "$url" ) || return 1
59}
60
61#open-file -s spawn "$text" || \
62tryurl "$text" || \
63trymail "$text" || \
64tryman "$text" || \
65choice

Generated with cgit - Back to sebastiano.tronto.net