aboutsummaryrefslogtreecommitdiff
path: root/xplumb
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-06-10 18:58:52 +0200
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-06-10 18:58:52 +0200
commitb98e05ba63f2e108df634b4d9f9e5530769c6b80 (patch)
treea1d3a7f20e826d264f2a6b2141b7b1bfa7debb6f /xplumb
parented61c5f085cebb86d3d3a34ce01ec22069c1fc70 (diff)
downloadscripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.tar.gz
scripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.zip
Added scripts and readme
Diffstat (limited to '')
-rwxr-xr-xxplumb66
1 files changed, 66 insertions, 0 deletions
diff --git a/xplumb b/xplumb
new file mode 100755
index 0000000..977d2d5
--- /dev/null
+++ b/xplumb
@@ -0,0 +1,66 @@
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, websearch, xsel
9
10# TODO:
11# send mail to email address;
12# calendar if it is a date
13# choice: pipe to another program
14
15browser=${BROWSER:-firefox}
16terminal=${TERMINAL:-xterm}
17xeditor=${XEDITOR:-gedit}
18menu=${MENU:-dmenu}
19menuopts="-l 10"
20
21text=$(xsel | sed 's/\n/ /g')
22if [ $(echo "$text" | wc -c) -ge 11 ]; then
23 shorttext=$(echo "$text" | cut -b 1-10)...
24else
25 shorttext="$text"
26fi
27
28choice() {
29 chosen=$(printf "websearch\nedit" | \
30 $menu $menuopts -p "What to do with \"$shorttext\"?")
31
32 if [ "$chosen" = "websearch" ]; then
33 websearch $text
34 elif [ "$chosen" = "edit" ]; then
35 f=$(mktemp)
36 xsel > "$f"
37 $xeditor "$f"
38 fi
39}
40
41trymail() {
42 addr=$(echo "$1" | addressgrep)
43 ( [ -n "$addr" ] && mail-compose $addr ) || return 1
44}
45
46tryman() {
47 number=$(echo "$1" | sed 's/[^1-8]//g')
48 name=$(echo "$1" | sed 's/([1-8])//g' | sed 's/ //g')
49 if [ $(man -w "$number" "$name" | wc -l) = 1 ]; then
50 $terminal -e man "$number" "$name"
51 return 0
52 else
53 return 1
54 fi
55}
56
57tryurl() {
58 url=$(echo "$1" | urlgrep)
59 ( [ -n "$url" ] && $browser $url ) || return 1
60}
61
62open-file "$text" || \
63tryurl "$text" || \
64trymail "$text" || \
65tryman "$text" || \
66choice

Generated with cgit - Back to sebastiano.tronto.net