In light of the recent interest in fish shell, the equivalent in fish is:
function clip
if not tty >/dev/null
pbcopy
else
pbpaste
end
end