Mirrored from GitHub

Jump to: README.md ploomb.sh


README.md

1	# ploomb <sub>(plumbing in Linux)</sub>
2	
3	this is a POSIX script for 'plumbing' text as search queries to websites
4	
5	## What is plumbing?
6	
7	Plumbing is a mechanism for passing messages between applications. It has a customizable set of rules (see `plumb(6)`) to process incoming messages and dispatch them to target applications.
8	
9	The `plumber(4)` is the file server that performs the message processing and dispatch.
10	
11	It is up to each application how it wishes to use this mechanism, but in the user-interface domain, the mechanism often allows the user to point to a file-name or URL and have the associated resource processed by an appropriate application.
12	
13	— [9p.io/wiki/plan9/using_plumbing/](https://9p.io/wiki/plan9/using_plumbing/)
14	
15	## Using ploomb
16	
17	- Bind to a key: [ploomb](//git.bauherren.ovh/ploomb)
18	- Highlight a word/sentence in your graphical application
19	- Run `ploomb`
20	- Select an option from `dmenu`
21	
22	## Thanks
23	
24	- [Plumbing in Linux (a la Plan 9 from Bell Labs), by Luke Smith](//youtu.be/RlMxbQmMz_4?si=lQNjGDTkD1qvvUfw)  
25	  - Author of *cabl*, a BASH script to bring the concept of plumbing to Linux. Discusses using *cabl* without a mouse.
26	
27	- [Plumbing for language learners](//tatsumoto-ren.github.io/blog/plumbing-for-language-learners.html)  
28	  - Adds replete and more complex functions to Luke's *cabl* script, tailored to language learning.
29	
30	## Author
31	
32	Forward complaints to [christos@bauherren.ovh](mailto:christos@bauherren.ovh)
33	

ploomb.sh

1	#!/bin/sh
2	
3	search_text="$( { xclip -o || xclip -o -selection clipboard; } | tr '[:upper:]' '[:lower:]')"
4	
5	readonly search_text
6	
7	search() {
8	    "$BROWSER" "https://google.com/search?q=$*"
9	}
10	
11	wiki() {
12		"$BROWSER" "https://en.wikipedia.org/wiki/$*"
13	}
14	
15	mal() {
16		"$BROWSER" "https://myanimelist.net/search/all?q=$*"
17	}
18	
19	yab() {
20		"$BROWSER" "https://chinese.yabla.com/chinese-english-pinyin-dictionary.php?define=$*"
21	}
22	
23	yb() {
24		"$BROWSER" "https://yellowbridge.com/chinese/sentsearch.php?word=$*"
25	}
26	
27	web() {
28	    "$BROWSER" "$@"
29	}
30	
31	ety() {
32	    "$BROWSER" "https://en.wiktionary.org/wiki/$*"
33	}
34	
35	yt() {
36		"$BROWSER" "https://www.youtube.com/results?search_query=$*"
37	}
38	
39	__ask_action() {
40	    declare -F | awk '!/ __.+$/ {gsub("_", " ", $3); print $3}' |
41	        dmenu -p "Send ${search_text:0:30} to?" -i -l 50
42	}
43	
44	__main() {
45	    if [ -n "${func:=$(__ask_action)}" ]; then
46	        "${func// /_}" "$search_text"
47	    fi
48	}
49	
50	__main