Before I built the screenshotpaste tool from my previous post I was interacting with a lot more agents and found myself wanting to copy paths quickly. I have long been a fan of the pbcopy & pbpaste commands and wanted something similar for paths. Realpath was what I needed but I wrote a small wrapper around it called cpath:

cpath() {
  if [ -z "$1" ]; then
    pwd | tr -d '\n' | pbcopy && echo 'pwd copied to clipboard'
  else
    realpath "$1" | tr -d '\n' | pbcopy && echo "Path copied: $(realpath "$1")"
  fi
}

This has been quite useful - if you’re curious to learn more about how NSPasteboard works I recommend this neat post.