1
0
mirror of https://github.com/samoshkin/tmux-config.git synced 2026-01-03 00:08:01 +00:00

Make possible to share remote and local copy buffer via local listener, SSH remote tunnel and nc on remote host

This commit is contained in:
Alexey Samoshkin
2017-11-24 20:49:27 +02:00
parent 572dcfcd8c
commit 86d1c9d3b0
2 changed files with 9 additions and 4 deletions

View File

@@ -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}"

View File

@@ -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 )