diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-06-10 18:58:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-06-10 18:58:52 +0200 |
| commit | b98e05ba63f2e108df634b4d9f9e5530769c6b80 (patch) | |
| tree | a1d3a7f20e826d264f2a6b2141b7b1bfa7debb6f /xplumb | |
| parent | ed61c5f085cebb86d3d3a34ce01ec22069c1fc70 (diff) | |
| download | scripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.tar.gz scripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.zip | |
Added scripts and readme
Diffstat (limited to '')
| -rwxr-xr-x | xplumb | 66 |
1 files changed, 66 insertions, 0 deletions
| @@ -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 | |||
| 15 | browser=${BROWSER:-firefox} | ||
| 16 | terminal=${TERMINAL:-xterm} | ||
| 17 | xeditor=${XEDITOR:-gedit} | ||
| 18 | menu=${MENU:-dmenu} | ||
| 19 | menuopts="-l 10" | ||
| 20 | |||
| 21 | text=$(xsel | sed 's/\n/ /g') | ||
| 22 | if [ $(echo "$text" | wc -c) -ge 11 ]; then | ||
| 23 | shorttext=$(echo "$text" | cut -b 1-10)... | ||
| 24 | else | ||
| 25 | shorttext="$text" | ||
| 26 | fi | ||
| 27 | |||
| 28 | choice() { | ||
| 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 | |||
| 41 | trymail() { | ||
| 42 | addr=$(echo "$1" | addressgrep) | ||
| 43 | ( [ -n "$addr" ] && mail-compose $addr ) || return 1 | ||
| 44 | } | ||
| 45 | |||
| 46 | tryman() { | ||
| 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 | |||
| 57 | tryurl() { | ||
| 58 | url=$(echo "$1" | urlgrep) | ||
| 59 | ( [ -n "$url" ] && $browser $url ) || return 1 | ||
| 60 | } | ||
| 61 | |||
| 62 | open-file "$text" || \ | ||
| 63 | tryurl "$text" || \ | ||
| 64 | trymail "$text" || \ | ||
| 65 | tryman "$text" || \ | ||
| 66 | choice | ||
