summaryrefslogtreecommitdiff
path: root/plugins/copypath/copypath.plugin.zsh
blob: 8fe0a85f412f7db11f39b6d33ed43e0c171172a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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."}
}