feat(copypath): add plugin to copy file paths to clipboard (#7569)

Closes #7569
Closes #10714
This commit is contained in:
Marc Cornellà 2022-02-22 11:18:43 +01:00
parent b00b59364a
commit 11a23144ad
No known key found for this signature in database
GPG Key ID: 0314585E776A9C1B
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# copypath plugin
Copies the path of given directory or file to the system clipboard.
To use it, add `copypath` to the plugins array in your zshrc file:
```zsh
plugins=(... copypath)
```
## Usage
- `copypath`: copies the absolute path of the current directory.
- `copypath <file_or_directory>`: copies the absolute path of the given file.

View File

@ -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."}
}