summaryrefslogtreecommitdiffstats
path: root/bridge/lib/bridge/bin/paste
blob: d3ed1fc531090dc6e5bd444d971a34021a4a9d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /bin/sh
#
# Paste some data to a session.
#
## SYNOPSIS
#
#     bridge paste SESSION DATA...
#     bridge paste SESSION < DATA
#
set -euf

target="$1"; shift

# paste args or stdin
if test $# -gt 0; then
  tmux -L bridge set-buffer -b 0 "$*"
else
  # use aux file instead of direct stdin for Vim and when used from $SHELL
  if test -n "${VIMRUNTIME-}" || tty >/dev/null; then
    path=`mktemp`
    trap "rm -f $path" EXIT INT TERM
    cat>$path
  else
    path=-
  fi
  tmux -L bridge load-buffer -b 0 $path
fi

tmux -L bridge paste-buffer -b 0 -t "$target"
tmux -L bridge   set-buffer -b 0 READY.