You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.4 KiB

  1. #!/bin/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. PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3)
  7. PID=$(echo "$(pstree -lpA "$PID" | tail -n 1)" | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')
  8. cd "$(readlink /proc/"$PID"/cwd)"
  9. [[ "${prim}" == *"~"* ]] && prim=$(echo "~/go/src/gitlab.com/tovijaeschke/website" | sed 's@~@'"$HOME"'@g')
  10. [ -f "$prim" ] && xdg-open "$prim" && exit
  11. [ -d "$prim" ] && st -c "$prim" && exit
  12. websearch() { "$BROWSER" "https://duckduckgo.com/?q=$@" ;}
  13. wikipedia() { "$BROWSER" "https://en.wikipedia.org/wiki/$@" ;}
  14. wiktionary() { "$BROWSER" "https://en.wiktionary.org/wiki/$@" ;}
  15. piratebay() { "$BROWSER" "https://piratebays.fi/s/?q=$@" ;}
  16. maps() { "$BROWSER" "https://www.openstreetmap.org/search?query=$@" ;}
  17. ebay() { "$BROWSER" "https://www.ebay.com/sch/$@" ;}
  18. echo "$prim" | grep "^.*\.[A-Za-z]\+.*" >/dev/null && gotourl() { "$BROWSER" "$@" ;}
  19. echo "$prim" | grep "^.*@.*\.[A-Za-z]\+$" >/dev/null && email() { xdg-email "$@" ;}
  20. command -v qrencode >/dev/null && qrcode() { qrencode "$@" -s 10 -o /tmp/qr.png && xdg-open /tmp/qr.png ;}
  21. man -k "^$prim$" >/dev/null && manual() { man -Tpdf "$prim" | zathura - ;}
  22. func="$(declare -F | awk '{print $3}' | dmenu -p "Plumb $prim to?" -i -l 15)"
  23. [ -z "$func" ] || "$func" "$prim"