b6d78df62c540245f67ffc900d0b1a17a6dfb77e

Author
Andrew Janke <andrew@apjanke.net>
Committer
Andrew Janke <andrew@apjanke.net>
Date

Message

clip*: add xsel support

Diff

 1diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh
 2index 24b7380f71bac57bd044a41c3639e143944e098a..b663800a4d09bb9918d5f33d3188c81d58ea8882 100644
 3--- a/lib/clipboard.zsh
 4+++ b/lib/clipboard.zsh
 5@@ -31,15 +31,21 @@ function clipcopy() {
 6       cat $file > /dev/clipboard
 7     fi
 8   else
 9-    which xclip &>/dev/null
10-    if [[ $? != 0 ]]; then
11-      print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2
12-      return 1
13-    fi
14-    if [[ -z $file ]]; then
15-      xclip -in -selection clipboard
16+    if which xclip &>/dev/null; then
17+      if [[ -z $file ]]; then
18+        xclip -in -selection clipboard
19+      else
20+        xclip -in -selection clipboard $file
21+      fi
22+    elif which xsel &>/dev/null; then
23+      if [[ -z $file ]]; then
24+        xsel --clipboard --input 
25+      else
26+        cat "$file" | xsel --clipboard --input
27+      fi
28     else
29-      xclip -in -selection clipboard $file
30+      print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
31+      return 1
32     fi
33   fi
34 }
35@@ -50,6 +56,17 @@ function clipcopy() {
36 #
37 #   clippaste   - writes clipboard's contents to stdout
38 #
39+#   clippaste | <command>    - pastes contents and pipes it to another process
40+#
41+#   clippaste > <file>      - paste contents to a file
42+#
43+# Examples:
44+#
45+#   # Pipe to another process
46+#   clippaste | grep foo
47+#
48+#   # Paste to a file
49+#   clippaste > file.txt
50 function clippaste() {
51   emulate -L zsh
52   if [[ $OSTYPE == darwin* ]]; then
53@@ -57,11 +74,13 @@ function clippaste() {
54   elif [[ $OSTYPE == cygwin* ]]; then
55     cat /dev/clipboard
56   else
57-    which xclip &>/dev/null 
58-    if [[ $? != 0 ]]; then
59-      print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2
60+    if which xclip &>/dev/null; then
61+      xclip -out -selection clipboard
62+    elif which xsel &>/dev/null; then
63+      xsel --clipboard --output
64+    else
65+      print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
66       return 1
67     fi
68-    xclip -out -selection clipboard
69   fi
70-}
71+}
72diff --git a/plugins/copydir/copydir.plugin.zsh b/plugins/copydir/copydir.plugin.zsh
73index 4b918e815edc3d187902d61e95ac3c151feb6ca7..c451062406a0a3fab62728e673c94f6cab5b396c 100644
74--- a/plugins/copydir/copydir.plugin.zsh
75+++ b/plugins/copydir/copydir.plugin.zsh
76@@ -2,4 +2,4 @@
77 function copydir {
78   emulate -L zsh
79   print -n $PWD | clipcopy
80-}
81+}