浏览代码

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.
Robert Estelle 5 年之前
父节点
当前提交
d855547661
共有 1 个文件被更改,包括 6 次插入21 次删除
  1. 6 21
      lib/clipboard.zsh

+ 6 - 21
lib/clipboard.zsh

@@ -17,32 +17,17 @@
 #
 #
 function clipcopy() {
 function clipcopy() {
   emulate -L zsh
   emulate -L zsh
-  local file=$1
+  local file="${1:-/dev/stdin}"
+
   if [[ $OSTYPE == darwin* ]]; then
   if [[ $OSTYPE == darwin* ]]; then
-    if [[ -z $file ]]; then
-      pbcopy
-    else
-      cat $file | pbcopy
-    fi
+    pbcopy < "${file}"
   elif [[ $OSTYPE == cygwin* ]]; then
   elif [[ $OSTYPE == cygwin* ]]; then
-    if [[ -z $file ]]; then
-      cat > /dev/clipboard
-    else
-      cat $file > /dev/clipboard
-    fi
+    cat "${file}" > /dev/clipboard
   else
   else
     if (( $+commands[xclip] )); then
     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
     elif (( $+commands[xsel] )); then
-      if [[ -z $file ]]; then
-        xsel --clipboard --input 
-      else
-        cat "$file" | xsel --clipboard --input
-      fi
+      xsel --clipboard --input  < "${file}"
     else
     else
       print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
       print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
       return 1
       return 1