helm/bin/rclip
2017-12-18 01:12:13 -05:00

47 lines
1,010 B
Bash
Executable file

#!/usr/bin/env bash
# A simple script for sending data to another computer's clipboard via SSH. Acts
# as a universal clipboard. This script must be available on the remote. Pipe
# through gpg if you want the contents encrypted.
#
# It helps if your ssh connection is pubkey authenticated and password-less.
#
# Requires: pb (script, in same folder)
#
# Workflow:
# host $ echo "Hello world!" | rclip guest
# guest $ rclip
# Hello world!
# OR
# host $ echo "Hello world!" | gpg -e | rclip.sh guest
# guest $ rclip | gpg -d
# Hello world!
bin="${0##*/}"
flags=
while getopts p:i:l: opt; do
case $opt in
p) flags+=" -p $OPTARG" ;;
i) flags+=" -i $OPTARG" ;;
l) flags+=" -l $OPTARG" ;;
*) >&2 echo "Invalid option $OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))
target="$1"
if [[ $target ]]; then
if [[ -t 0 ]]; then
pb | $bin $target
else
ssh $flags -qt "$target" "pb" && echo "Sent to $target"
fi
else
pb
fi
# vim:set ft=sh: