736632228a5f39573a15f4533b7672851f30bbe6

Author
0xHouss <67522466+0xHouss@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(copyfile): add error handling (#13248)

Diff

 1diff --git a/plugins/copyfile/copyfile.plugin.zsh b/plugins/copyfile/copyfile.plugin.zsh
 2index f4eca5acf82c6b20a5aabaeed81add2117e636c3..3281410e5c5b93a5d35101a8bc77d02a08d26ec5 100644
 3--- a/plugins/copyfile/copyfile.plugin.zsh
 4+++ b/plugins/copyfile/copyfile.plugin.zsh
 5@@ -1,7 +1,19 @@
 6 # Copies the contents of a given file to the system or X Windows clipboard
 7 #
 8-# copyfile <file>
 9+# Usage: copyfile <file>
10 function copyfile {
11   emulate -L zsh
12+
13+  if [[ -z "$1" ]]; then
14+    echo "Usage: copyfile <file>"
15+    return 1
16+  fi
17+
18+  if [[ ! -f "$1" ]]; then
19+    echo "Error: '$1' is not a valid file."
20+    return 1
21+  fi
22+
23   clipcopy $1
24+  echo ${(%):-"%B$1%b copied to clipboard."}
25 }