summaryrefslogtreecommitdiff
path: root/lib/clipboard.zsh
diff options
context:
space:
mode:
authorAndrew Janke <andrew@apjanke.net>2015-10-04 03:42:24 -0400
committerAndrew Janke <andrew@apjanke.net>2015-10-05 05:13:11 -0400
commitb6d78df62c540245f67ffc900d0b1a17a6dfb77e (patch)
tree5b4f358989828f99185266c8544f3f4c8fa0f9bb /lib/clipboard.zsh
parente4fdb083655fc582ebcecb07cd1bd1130077f0e4 (diff)
downloadzsh-b6d78df62c540245f67ffc900d0b1a17a6dfb77e.tar.gz
zsh-b6d78df62c540245f67ffc900d0b1a17a6dfb77e.tar.bz2
zsh-b6d78df62c540245f67ffc900d0b1a17a6dfb77e.zip
clip*: add xsel support
Diffstat (limited to 'lib/clipboard.zsh')
-rw-r--r--lib/clipboard.zsh45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh
index 24b7380f7..b663800a4 100644
--- a/lib/clipboard.zsh
+++ b/lib/clipboard.zsh
@@ -31,15 +31,21 @@ function clipcopy() {
cat $file > /dev/clipboard
fi
else
- which xclip &>/dev/null
- if [[ $? != 0 ]]; then
- print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2
- return 1
- fi
- if [[ -z $file ]]; then
- xclip -in -selection clipboard
+ if which xclip &>/dev/null; then
+ if [[ -z $file ]]; then
+ xclip -in -selection clipboard
+ else
+ xclip -in -selection clipboard $file
+ fi
+ elif which xsel &>/dev/null; then
+ if [[ -z $file ]]; then
+ xsel --clipboard --input
+ else
+ cat "$file" | xsel --clipboard --input
+ fi
else
- xclip -in -selection clipboard $file
+ print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
+ return 1
fi
fi
}
@@ -50,6 +56,17 @@ function clipcopy() {
#
# clippaste - writes clipboard's contents to stdout
#
+# clippaste | <command> - pastes contents and pipes it to another process
+#
+# clippaste > <file> - paste contents to a file
+#
+# Examples:
+#
+# # Pipe to another process
+# clippaste | grep foo
+#
+# # Paste to a file
+# clippaste > file.txt
function clippaste() {
emulate -L zsh
if [[ $OSTYPE == darwin* ]]; then
@@ -57,11 +74,13 @@ function clippaste() {
elif [[ $OSTYPE == cygwin* ]]; then
cat /dev/clipboard
else
- which xclip &>/dev/null
- if [[ $? != 0 ]]; then
- print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2
+ if which xclip &>/dev/null; then
+ xclip -out -selection clipboard
+ elif which xsel &>/dev/null; then
+ xsel --clipboard --output
+ else
+ print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1
fi
- xclip -out -selection clipboard
fi
-} \ No newline at end of file
+}