cabl (1334B)
1 #!/usr/bin/env bash 2 # Dependencies are xclip and xorg-xprop. 3 # qrencode required for qrcode generation. 4 # groff/zathura required for man pages. 5 prim="$(xclip -o)"; [ -z "$prim" ] && exit 6 7 PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3) 8 PID=$(echo "$(pstree -lpA "$PID" | tail -n 1)" | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') 9 cd "$(readlink /proc/"$PID"/cwd)" 10 [ -f "$prim" ] && xdg-open "$prim" && exit 11 [ -d "$prim" ] && "$TERMINAL" "$prim" && exit 12 13 websearch() { "$BROWSER" "https://duckduckgo.com/?q=$@" ;} 14 wikipedia() { "$BROWSER" "https://en.wikipedia.org/wiki/$@" ;} 15 wiktionary() { "$BROWSER" "https://en.wiktionary.org/wiki/$@" ;} 16 maps() { "$BROWSER" "https://www.openstreetmap.org/search?query=$@" ;} 17 ebay() { "$BROWSER" "https://www.ebay.com/sch/$@" ;} 18 19 echo "$prim" | grep "^.*\.[A-Za-z]\+.*" >/dev/null && gotourl() { "$BROWSER" "$@" ;} 20 echo "$prim" | grep "^.*@.*\.[A-Za-z]\+$" >/dev/null && email() { xdg-email "$@" ;} 21 command -v qrencode >/dev/null && qrcode() { qrencode "$@" -s 10 -o /tmp/qr.png && xdg-open /tmp/qr.png ;} 22 man -k "^$prim$" >/dev/null && manual() { man -Tpdf "$prim" | zathura - ;} 23 24 func="$(declare -F | awk '{print $3}' | dmenu -p "Plumb \"$(echo "$prim" | cut -c -30)\" to?" -i -l 15)" 25 26 [ -z "$func" ] || "$func" "$prim"