Add copy and paste aliases to clipboard commands

Interact with the clipboard through the `copy` and `paste` aliases.

`copy` is defined when:

1. An `ssh` connection is detected, using OSC-52.
2. macOS is detected, using `pbcopy`.
3. `xsel` is detected.

`paste` is define when:

1. macOS is detected, using `pbpaste`.
2. `xsel` is detected.
This commit is contained in:
Kenneth Benzie 2021-03-02 20:04:33 +00:00
parent d91d6b3534
commit b694e9cdf5

View File

@ -2,6 +2,25 @@
autoload colors && colors
# Abstract different ways to copy to the clipboard.
if [ -n "$SSH_CONNECTION" ] ; then
# Use OSC-52 to set the clipboard
alias copy='base64 | xargs -0 printf "\033]52;c;%s\a"'
elif [ "`uname`" = "Darwin" ]; then
# Use pbcopy to set the clipboard
alias copy='pbcopy'
elif which xclip &> /dev/null; then
# Use xclip to set the clipboard
alias copy='xclip -selection c'
fi
# Abstract different ways to paste from the clipboard.
if [ "`uname`" = "Darwin" ]; then
alias paste='pbpaste'
elif which xclip &> /dev/null; then
alias paste='xclip -selection c -o'
fi
# Detect the type and extract an archive file.
extract() {
if [ -f $1 ]; then