os/shell/ CopyPaste
pc - copy to clipboard
#!/bin/bash
# copy to clipboard
if [ -n "$DISPLAY" ]; then # X11
cat "$@" | xsel -i -b
elif [ -d "/Applications" ]; then # macos
cat "$@" | pbcopy
elif [ -d "/cygdrive/c/cygwin64" ]; then # cygwin
cat "$@" > /dev/clipboard
else
echo "Cannot copy as not gui" > /dev/stderr
fi
pcw - use which to find a file and copy that to the clipboard
#!/bin/bash
a="$(which "$1")"
if exists "$a"; then
pc "$a"
fi
pp - paste from clipboard, to stdout, and possibly to named files (use -y switch to enable clobbering, else it will not overwrite)
#!/bin/bash
if [ -n "$DISPLAY" ]; then # X11
paste() { xsel -o -b; }
elif [ -d "/Applications" ]; then # macos
paste() { pbpaste; }
elif [ -d "/cygdrive/c/cygwin64" ]; then # cygwin
paste() { cat /dev/clipboard; }
else
echo "Cannot paste as not gui" > /dev/stderr
fi
clobber=n
if [ $# = 0 ]; then
paste
exit
fi
for s; do
if [ "$s" = "-y" ]; then
clobber=y
continue
fi
if [ -n "$s" ]; then
if [ "$clobber" = "y" -o ! -e "$s" ]; then
paste | tee "$s"
elif [ -e "$s" ]; then
echo "Not overwriting $s"
fi
else
paste
fi
done