helm/bin/rclip

47 lines
1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2017-04-25 18:57:49 -07:00
# 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.
#
2017-04-25 18:57:49 -07:00
# Requires: pb (script, in same folder)
#
# Workflow:
2017-04-25 18:57:49 -07:00
# host $ echo "Hello world!" | rclip guest
# guest $ rclip
# Hello world!
# OR
2017-01-03 00:44:35 -08:00
# host $ echo "Hello world!" | gpg -e | rclip.sh guest
2017-04-25 18:57:49 -07:00
# 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))
2017-04-25 18:57:49 -07:00
target="$1"
if [[ $target ]]; then
if [[ -t 0 ]]; then
pb | $bin $target
else
2017-04-25 18:57:49 -07:00
ssh $flags -qt "$target" "pb" && echo "Sent to $target"
fi
else
2017-04-25 18:57:49 -07:00
pb
fi
# vim:set ft=sh: