pbcopy and pbpaste are handy, for a version that works over ssh connections there is osc: https://github.com/theimpostor/osc
replies(4):
if [[ "$(uname)" == "Darwin" ]]; then
clip() {
[ -t 0 ] && pbpaste || pbcopy
}
else # assume linux if not macos
clip() {
[ -t 0 ] && xclip -o -selection clipboard || xclip -selection clipboard
}
fi