aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-06-26 15:20:48 +0200
committerMattias Andrée <maandree@kth.se>2021-06-26 15:20:48 +0200
commit316779978732ee99d446a36c0cfad5e5730b2142 (patch)
tree9cef8ae1ec03f314b331745450fe36698dc3478d
parentAdd xkbdbind (diff)
downloaddotfiles-316779978732ee99d446a36c0cfad5e5730b2142.tar.gz
dotfiles-316779978732ee99d446a36c0cfad5e5730b2142.tar.bz2
dotfiles-316779978732ee99d446a36c0cfad5e5730b2142.tar.xz
Add plumb script
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--dmenu/Makefile2
-rwxr-xr-xdmenu/plumb98
2 files changed, 100 insertions, 0 deletions
diff --git a/dmenu/Makefile b/dmenu/Makefile
index 151ba9c..85e0681 100644
--- a/dmenu/Makefile
+++ b/dmenu/Makefile
@@ -9,11 +9,13 @@ install:
ln -sf -- ~/.dotfiles/dmenu/man ~/.local/bin/
ln -sf -- ~/.dotfiles/dmenu/ipa ~/.local/bin/
ln -sf -- ~/.dotfiles/dmenu/unicode ~/.local/bin/
+ ln -sf -- ~/.dotfiles/dmenu/plumb ~/.local/bin/
uninstall:
-unlink -- ~/.local/bin/man
-unlink -- ~/.local/bin/ipa
-unlink -- ~/.local/bin/unicode
+ -unlink -- ~/.local/bin/plumb
-make -C unicode.d reallyclean
.PHONY: install uninstall
diff --git a/dmenu/plumb b/dmenu/plumb
new file mode 100755
index 0000000..13cfca8
--- /dev/null
+++ b/dmenu/plumb
@@ -0,0 +1,98 @@
+#!/bin/bash
+
+WEB_BROWSER=brave
+EMAIL_CLIENT=claws-mail
+if test -x /usr/bin/terminator; then
+ TERMINAL=terminator
+elif test -x /usr/bin/st; then
+ TERMINAL=st
+else
+ TERMINAL=xterm
+fi
+
+sel="$(xclip -o)"
+url="$(printf '%s' "$sel" | tr -d '\n')"
+file="$(printf '%s' "$sel" | tr -d '\n')"
+
+if test -z "$sel"; then
+ exit 0
+fi
+
+cd -- "$(readlink "/proc/$(pstree -lpA "$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep PID | head -n 1 | cut -d ' ' -f 3)" | awk -F--- '{print $NF}' | tail -n1 | tr -Cd '[0-9]')/cwd")"
+
+functions=""
+
+if test -d "$sel" || test -d "$(printf '%s\n' "$sel" | sed 's|^~/|'"${HOME}|")"; then
+ functions="$functions caja terminal"
+ caja () {
+ exec c "$sel";
+ }
+ terminal () {
+ cd -- "$sel"
+ exec $TERMINAL;
+ }
+elif test -e "$sel"; then
+ functions="$functions open"
+ open () {
+ exec xdg-open -- "$url";
+ }
+fi
+
+if printf '%s\n' "$url" | grep '^\(https\?://\|www\.\)[^[:space:]./]\+\.[^[:space:]/]*\(/\S*\)\?$' > /dev/null; then
+ if printf '%s\n' "$url" | grep '^\(https\?://\)\?\(www\.\)\?spreaker\.com/.*/.*/.*' > /dev/null; then
+ functions="$functions spreaker-dl"
+ spreaker-dl () {
+ cd ~/next/new
+ exec spreaker-dl "$url";
+ }
+ fi
+ functions="$functions web-browser"
+ web-browser () {
+ exec $WEB_BROWSER -- "$url";
+ }
+fi
+
+if printf '%s\n' "$url" | grep '^\(mailto:\)\?\("[^"]\+"\|[a-zA-Z0-9!#$%&'\''*+/=?^_`{|}~-]\+\(\.[a-zA-Z0-9!#$%&'\''*+/=?^_`{|}~-]\)*\)@[^[:space:]./]\+\.[^[:space:]/]*$' > /dev/null; then
+ functions="$functions email-client"
+ email-client () {
+ exec $EMAIL_CLIENT -- "$url";
+ }
+fi
+
+if test -r "$file" && file "$file" | grep '\(PNG\|JPEG\) image' > /dev/null; then
+ functions="$functions xwallpaper"
+ xwallpaper () {
+ exec xwallpaper --zoom "$file";
+ }
+fi
+
+functions="$functions wiktionary.en"
+wiktionary.en () {
+ exec $WEB_BROWSER "https://en.wiktionary.org/wiki/$sel";
+}
+
+functions="$functions wiktionary.sv"
+wiktionary.sv () {
+ exec $WEB_BROWSER "https://sv.wiktionary.org/wiki/$sel";
+}
+
+functions="$functions wikipedia.en"
+wikipedia.en () {
+ exec $WEB_BROWSER "https://en.wikipedia.org/wiki/$sel";
+}
+
+functions="$functions wikipedia.sv"
+wikipedia.sv () {
+ exec $WEB_BROWSER "https://sv.wikipedia.org/wiki/$sel";
+}
+
+functions="$functions duckduckgo"
+duckduckgo () {
+ exec $WEB_BROWSER "https://duckduckgo.com/?q=$sel";
+}
+
+function="$(printf '%s\n' $functions | dmenu -i -p "Plumb $sel to:" -l 50)"
+
+if test -n "$function"; then
+ "$function"
+fi