copypath.plugin.zsh 523 B

123456789101112131415
  1. # Copies the path of given directory or file to the system or X Windows clipboard.
  2. # Copy current directory if no parameter.
  3. function copypath {
  4. # If no argument passed, use current directory
  5. local file="${1:-.}"
  6. # If argument is not an absolute path, prepend $PWD
  7. [[ $file = /* ]] || file="$PWD/$file"
  8. # Copy the absolute path without resolving symlinks
  9. # If clipcopy fails, exit the function with an error
  10. print -n "${file:a}" | clipcopy || return 1
  11. echo ${(%):-"%B${file:a}%b copied to clipboard."}
  12. }