diff --git a/tmux/tmux.remote.conf b/tmux/tmux.remote.conf index e121be2..ea385bc 100644 --- a/tmux/tmux.remote.conf +++ b/tmux/tmux.remote.conf @@ -2,6 +2,9 @@ # so it do not stack together with local session's one set -g status-position bottom +# Set port of SSH remote tunnel, where tmux will pipe buffers to transfer on local machine for copy +set -g @copy_backend_remote_tunnel_port 11988 + # In remote mode we don't show "clock" and "battery status" widgets set -g status-left "$wg_session" set -g status-right "#{prefix_highlight} $wg_is_keys_off $wg_is_zoomed #{sysstat_cpu} | #{sysstat_mem} | #{sysstat_loadavg} | $wg_user_host | #{online_status}" diff --git a/tmux/yank.sh b/tmux/yank.sh index 219d7ce..653cc05 100755 --- a/tmux/yank.sh +++ b/tmux/yank.sh @@ -9,6 +9,8 @@ is_app_installed() { # get data either form stdin or from file buf=$(cat "$@") +copy_backend_remote_tunnel_port=$(tmux show-option -gvq "@copy_backend_remote_tunnel_port") + # Resolve copy backend: pbcopy (OSX), reattach-to-user-namespace (OSX), xclip/xsel (Linux) copy_backend="" if is_app_installed pbcopy; then @@ -19,17 +21,17 @@ elif [ -n "${DISPLAY-}" ] && is_app_installed xsel; then copy_backend="xsel -i --clipboard" elif [ -n "${DISPLAY-}" ] && is_app_installed xclip; then copy_backend="xclip -i -f -selection primary | xclip -i -selection clipboard" +elif [ -n "${copy_backend_remote_tunnel_port-}" ] && [ "$(ss -n -4 state listening "( sport = $copy_backend_remote_tunnel_port )" | tail -n +2 | wc -l)" -eq 1 ]; then + copy_backend="nc localhost $copy_backend_remote_tunnel_port" fi # if copy backend is resolved, copy and exit if [ -n "$copy_backend" ]; then - printf "$buf" | eval "$copy_backend" + printf "$buf" | eval "$copy_backend" exit; fi -# TODO: send to local socket which is remote tunneled to "pbcopy|xclip" listener on local machine -# TODO: otherwise fallback to OSC 52 escape sequence - +# If no copy backends were eligible, fallback to OSC 52 escape sequences # Copy via OSC 52 ANSI escape sequence to controlling terminal buflen=$( printf %s "$buf" | wc -c )