#!/bin/sh -e

case $(uname) in
  Darwin)
    pwd | sed "s|^${HOME}|~|" | tr -d '\n' | pbcopy
    # printf '%s' ${PWD/#$HOME/\~} | tr -d "\r\n" | pbcopy
    ;;
  *)
    pwd | sed "s|^${HOME}|~|" | tr -d '\n' | pbcopy
    # printf '%s' ${PWD/#$HOME/\~} | tr -d "\r\n" | pbcopy
    ;;
esac

# also copy current directory to a tmux paste buffer if tmux is active.
if [ -n "${TMUX}" ]; then
  pwd | sed "s|^${HOME}|~|" | tr -d "\r\n" | tmux load-buffer -
  # printf '%s' ${PWD/#$HOME/\~} | tr -d "\r\n" |
fi
