weechat-open-url 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. ## A script to handle opening urls from weechat in tmux, possibly on host maching
  3. ## Inspired by https://toxicfrog.github.io/remote-url-handling-in-weechat-and-tmux/
  4. ##
  5. ## This script is relying on the laptop opening a reverse ssh tunnel to the server
  6. ##
  7. ## Add binding for M-o #, for 1 through 9 (10 can be 0)
  8. ## /key bind meta-o1 /url_hint_replace /exec -bg weechat-open-url {url1}
  9. ## /key bind meta-o2 /url_hint_replace /exec -bg weechat-open-url {url2}
  10. ##
  11. ## You can chose between a split (split-window -h) or new (new-window) in tmux
  12. ## Reverse SSH Tunnel Check
  13. #laptop_status="$(nc -z localhost 2001 && echo 1 || echo 0)"
  14. ## VPN Check, nc faster than a ping
  15. laptop_status="$(nc -z -w 1 10.0.10.3 22 && echo 1 || echo 0)"
  16. laptop_host="wgdoom"
  17. function open-image {
  18. if [ ${laptop_status} == 1 ]; then
  19. ssh ${laptop_host} env DISPLAY=:0 feh -x -F --auto-zoom "'$1'"
  20. else
  21. tmux new-window -c ~ bash -c "timg $1 && read -s -n 1 -p 'Press Any Key to Exit'"
  22. fi
  23. }
  24. function open-url {
  25. if [ ${laptop_status} == 1 ]; then
  26. ssh ${laptop_host} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' /usr/share/qutebrowser/scripts/open_url_in_instance.sh "'$1'"
  27. else
  28. tmux new-window -c ~ bash -c "w3m '$1'"
  29. fi
  30. }
  31. function open-video {
  32. ## Only exec if laptop connected
  33. if [ ${laptop_status} == 1 ]; then
  34. ssh ${laptop_host} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' mpv --profile=rem "'$1'"
  35. fi
  36. }
  37. function open-sound {
  38. ## Only exec if laptop connected
  39. if [ ${laptop_status} == 1 ]; then
  40. ssh ${laptop_host} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' mpv --profile=pod "'$1'"
  41. fi
  42. }
  43. case $(echo "$1" | tr A-Z a-z) in
  44. *.jpg|*.jpeg|*.png|*.gif|*.svg|*:large)
  45. open-image "$1"
  46. ;;
  47. *youtube.com/*|*youtu.be/*|*.gifv|*.mp4|*.webm)
  48. open-video "$1"
  49. ;;
  50. *.mp3)
  51. open-sound "$1"
  52. ;;
  53. *)
  54. open-url "$1"
  55. ;;
  56. esac