#!/bin/sh -e
#
# rp - copies full file path of a given file to clipboard and
# print the current paths vcs root or home

while
  [ -n "${d:="${PWD}"}" ] \
    && [ ! -d "${d}/.git" ] \
    && [ ! -d "${d}/CVSROOT" ] \
    && [ "${d}" != "${HOME}" ]
do
  d="${d%/*}"
done && printf "%s\n" "${d}"

# shellcheck disable=SC2249
case "$#" in
  0) pwd | tr -d "\n" | pbcopy ;;              # copy cwd
  1) readlink -f "$1" | tr -d '\n' | pbcopy ;; # copy $1 path
esac
