1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-23 14:20:08 +00:00
ohmyzsh/plugins/copypath/copypath.plugin.zsh
2022-02-22 11:25:09 +01:00

15 lines
523 B
Bash

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