diff options
author | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
---|---|---|
committer | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
commit | edc449275b6c04445f58b108ca0937a87c1e8430 (patch) | |
tree | 9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/copypath | |
parent | 6f5424ca96c4221ef433f545642669e9c104d0ed (diff) |
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/copypath')
-rw-r--r-- | oh-my-zsh/plugins/copypath/README.md | 15 | ||||
-rw-r--r-- | oh-my-zsh/plugins/copypath/copypath.plugin.zsh | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/copypath/README.md b/oh-my-zsh/plugins/copypath/README.md new file mode 100644 index 0000000..1e5a463 --- /dev/null +++ b/oh-my-zsh/plugins/copypath/README.md @@ -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. diff --git a/oh-my-zsh/plugins/copypath/copypath.plugin.zsh b/oh-my-zsh/plugins/copypath/copypath.plugin.zsh new file mode 100644 index 0000000..8fe0a85 --- /dev/null +++ b/oh-my-zsh/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."} +} |