#! /bin/bash

help() {
  echo "Run a command and copy the output to the clipboard."
  echo "For example, run `color 3 copy pwd` to copy the current path."
  echo ""
  echo "`color 2 Usage:` copy <command> [args...]"
  echo ""
}

ARG1="$1"
if [[ $ARG1 ]]; then
  output=$(eval "$@")
  echo "$output"
  echo "$output" | pbcopy -selection clipboard
else
  help
fi
