summaryrefslogtreecommitdiff
path: root/plugins/copypath/copypath.plugin.zsh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
committerTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
commit2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945 (patch)
tree99add95300f57806b89bd885a5f5322ce9f9ac1a /plugins/copypath/copypath.plugin.zsh
parentcae9a2b797649379e865e6bd73bc67e294e4ac77 (diff)
parent53863e7b3ff0c2e2816e90dab3d870adebdf49c7 (diff)
downloadzsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.gz
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.bz2
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/copypath/copypath.plugin.zsh')
-rw-r--r--plugins/copypath/copypath.plugin.zsh15
1 files changed, 15 insertions, 0 deletions
diff --git a/plugins/copypath/copypath.plugin.zsh b/plugins/copypath/copypath.plugin.zsh
new file mode 100644
index 000000000..8fe0a85f4
--- /dev/null
+++ b/plugins/copypath/copypath.plugin.zsh
@@ -0,0 +1,15 @@
+# Copies the path of given directory or file to the system or X Windows clipboard.
+# Copy current directory if no parameter.
+function copypath {
+ # If no argument passed, use current directory
+ local file="${1:-.}"
+
+ # If argument is not an absolute path, prepend $PWD
+ [[ $file = /* ]] || file="$PWD/$file"
+
+ # Copy the absolute path without resolving symlinks
+ # If clipcopy fails, exit the function with an error
+ print -n "${file:a}" | clipcopy || return 1
+
+ echo ${(%):-"%B${file:a}%b copied to clipboard."}
+}