summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Estelle <robertestelle@gmail.com>2019-07-12 17:01:10 -0400
committerRobert Estelle <robertestelle@gmail.com>2019-07-12 17:45:57 -0400
commitd855547661ee4173bd01ab89ad18418d4dbf508a (patch)
tree7360b0e5ca62933186ae4b0ef2e866840406acab
parent29fb617e6b6b18fc7bdfef74fc57bbdf0e2fe52b (diff)
downloadzsh-d855547661ee4173bd01ab89ad18418d4dbf508a.tar.gz
zsh-d855547661ee4173bd01ab89ad18418d4dbf508a.tar.bz2
zsh-d855547661ee4173bd01ab89ad18418d4dbf508a.zip
clipboard: Reduce unnecessary special-casing on stdin
Ideally the parameter would just be removed-users could always just do "clipcopy < some-file". but removing the parameter would break backwards compatibility. In any case, this simplifies the logic considerably.
-rw-r--r--lib/clipboard.zsh27
1 files changed, 6 insertions, 21 deletions
diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh
index 2c93d1bb5..15ad6d916 100644
--- a/lib/clipboard.zsh
+++ b/lib/clipboard.zsh
@@ -17,32 +17,17 @@
#
function clipcopy() {
emulate -L zsh
- local file=$1
+ local file="${1:-/dev/stdin}"
+
if [[ $OSTYPE == darwin* ]]; then
- if [[ -z $file ]]; then
- pbcopy
- else
- cat $file | pbcopy
- fi
+ pbcopy < "${file}"
elif [[ $OSTYPE == cygwin* ]]; then
- if [[ -z $file ]]; then
- cat > /dev/clipboard
- else
- cat $file > /dev/clipboard
- fi
+ cat "${file}" > /dev/clipboard
else
if (( $+commands[xclip] )); then
- if [[ -z $file ]]; then
- xclip -in -selection clipboard
- else
- xclip -in -selection clipboard $file
- fi
+ xclip -in -selection clipboard < "${file}"
elif (( $+commands[xsel] )); then
- if [[ -z $file ]]; then
- xsel --clipboard --input
- else
- cat "$file" | xsel --clipboard --input
- fi
+ xsel --clipboard --input < "${file}"
else
print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1