Rewrite bin/{pb,rclip}
This commit is contained in:
parent
75683bac23
commit
f545be6b3f
4
bin/pb
4
bin/pb
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
if [[ -t 0 ]]; then
|
if [[ -t 0 ]]; then
|
||||||
if command -v xclip >/dev/null; then
|
if command -v xclip >/dev/null; then
|
||||||
xclip -selection clipboard -out
|
xclip -display :0 -selection clipboard -out
|
||||||
elif command -v xsel >/dev/null; then
|
elif command -v xsel >/dev/null; then
|
||||||
xsel --clipboard --output
|
xsel --clipboard --output
|
||||||
elif command -v pbpaste >/dev/null; then
|
elif command -v pbpaste >/dev/null; then
|
||||||
|
@ -16,7 +16,7 @@ if [[ -t 0 ]]; then
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if command -v xclip >/dev/null; then
|
if command -v xclip >/dev/null; then
|
||||||
xclip -selection clipboard -in
|
xclip -display :0 -selection clipboard -in
|
||||||
elif command -v xsel >/dev/null; then
|
elif command -v xsel >/dev/null; then
|
||||||
xsel --clipboard --input
|
xsel --clipboard --input
|
||||||
elif command -v pbcopy >/dev/null; then
|
elif command -v pbcopy >/dev/null; then
|
||||||
|
|
39
bin/rclip
39
bin/rclip
|
@ -1,30 +1,24 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Remote clipboard insertion via SSH
|
|
||||||
# By Henrik Lissner <henrik@lissner.net>
|
# 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
|
||||||
# A simple script for sending data to another computer's clipboard via SSH. Acts as
|
# through gpg if you want the contents encrypted.
|
||||||
# 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.
|
# It helps if your ssh connection is pubkey authenticated and password-less.
|
||||||
#
|
#
|
||||||
# If the destination (or host) is a mac, use pbcopy and pbpaste instead.
|
# Requires: pb (script, in same folder)
|
||||||
#
|
#
|
||||||
# Workflow:
|
# Workflow:
|
||||||
# host $ echo "Hello world!" | rclip.sh guest
|
# host $ echo "Hello world!" | rclip guest
|
||||||
# guest $ rclip.sh
|
# guest $ rclip
|
||||||
# Hello world!
|
# Hello world!
|
||||||
# OR
|
# OR
|
||||||
# host $ echo "Hello world!" | gpg -e | rclip.sh guest
|
# host $ echo "Hello world!" | gpg -e | rclip.sh guest
|
||||||
# guest $ rclip.sh | gpg -d
|
# guest $ rclip | gpg -d
|
||||||
# Hello world!
|
# Hello world!
|
||||||
|
|
||||||
pb=/tmp/rcopy-pb
|
|
||||||
bin="${0##*/}"
|
bin="${0##*/}"
|
||||||
|
|
||||||
copy() { [[ $OSTYPE == darwin* ]] && pbpaste; }
|
|
||||||
|
|
||||||
target="$1"
|
|
||||||
flags=
|
flags=
|
||||||
while getopts p:i:l: opt; do
|
while getopts p:i:l: opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
|
@ -38,20 +32,15 @@ while getopts p:i:l: opt; do
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
if [[ -t 1 || $force_output ]]; then
|
target="$1"
|
||||||
if [[ $target ]]; then
|
if [[ $target ]]; then
|
||||||
ssh $flags -qt "$target" "$bin"
|
if [[ -t 0 ]]; then
|
||||||
elif [[ $OSTYPE == darwin* ]]; then
|
pb | $bin $target
|
||||||
pbpaste
|
|
||||||
elif [[ -f $pb ]]; then
|
|
||||||
cat "$pb"
|
|
||||||
else
|
else
|
||||||
exit 1
|
ssh $flags -qt "$target" "pb" && echo "Sent to $target"
|
||||||
fi
|
fi
|
||||||
elif [[ $target ]]; then
|
|
||||||
ssh $flags -q "$target" "$bin"
|
|
||||||
else
|
else
|
||||||
tee "$pb" | copy
|
pb
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# vim:set ft=sh:
|
# vim:set ft=sh:
|
||||||
|
|
Loading…
Reference in a new issue