123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/bin/bash
- ## A script to handle opening urls from weechat in tmux, possibly on host maching
- ## Inspired by https://toxicfrog.github.io/remote-url-handling-in-weechat-and-tmux/
- ##
- ## This script is relying on the laptop opening a reverse ssh tunnel to the server
- ##
- ## Add binding for M-o #, for 1 through 9 (10 can be 0)
- ## /key bind meta-o1 /url_hint_replace /exec -bg weechat-open-url {url1}
- ## /key bind meta-o2 /url_hint_replace /exec -bg weechat-open-url {url2}
- ##
- ## You can chose between a split (split-window -h) or new (new-window) in tmux
- ## List of [wireguard] hosts to try for GUI viewing
- ## laptop, tablet
- host_list="10.0.10.3 10.0.10.6"
- function status_check {
- host_return="none"
- for h in ${host_list}; do
- ## Reverse SSH Tunnel Check
- ## VPN Check, nc faster than a ping
- if [ $(nc -z -w 1 ${h} 22 && echo 1 || echo 0) == 1 ]; then
- ## If host is reachable, set var and end testing
- host_return=${h}
- break
- fi
- done
- if [ ${host_return} != "none" ]; then
- host_use=${host_return}
- else
- host_use="none"
- fi
- }
- function source-ssh {
- ## Source SSH settings, if applicable
- local SSH_ENV="${HOME}/.ssh/environment"
- if [ -f "${SSH_ENV}" ]; then
- . "${SSH_ENV}" > /dev/null
- ps -ef 2>/dev/null | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
- pstree -up ${USER} 2>/dev/null | grep ${SSH_AGENT_PID} | grep ^ssh-agent > /dev/null || {
- __start_agent;
- }
- }
- fi
- }
- function open-image {
- if [[ ${host_use} != "none" ]]; then
- source-ssh
- ssh ${host_use} env DISPLAY=:0 feh -x -F --auto-zoom "'$1'"
- else
- tmux new-window -c ~ bash -c "timg $1 && read -s -n 1 -p 'Press Any Key to Exit'"
- fi
- }
- function open-url {
- if [[ ${host_use} != "none" ]]; then
- #ssh ${host_use} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' /usr/share/qutebrowser/scripts/open_url_in_instance.sh "'$1'"
- source-ssh
- ssh ${host_use} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' xdg-open "'$1'"
- else
- tmux new-window -c ~ bash -c "w3m '$1'"
- fi
- }
- function open-video {
- ## Only exec if laptop connected
- if [[ ${host_use} != "none" ]]; then
- source-ssh
- ssh ${host_use} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' mpv --profile=rem "'$1'"
- fi
- }
- function open-sound {
- ## Only exec if laptop connected
- if [[ ${host_use} != "none" ]]; then
- source-ssh
- ssh ${host_use} env DISPLAY=:0 'XDG_RUNTIME_DIR=/run/user/$(id -u)' mpv --profile=pod "'$1'"
- fi
- }
- status_check
- case $(echo "$1" | tr A-Z a-z) in
- *.jpg|*.jpeg|*.png|*.gif|*.svg|*:large)
- open-image "$1"
- ;;
- *youtube.com/*|*youtu.be/*|*.gifv|*.mp4|*.webm)
- open-video "$1"
- ;;
- *.mp3)
- open-sound "$1"
- ;;
- *)
- open-url "$1"
- ;;
- esac
|