set -e
if [ "$1" = "find" ] || [ "$1" = "search" ]; then
  website -l | grep "$2"
  exit 0
fi
if [ "$1" = "-l" ]; then
  ls $HOME/website
  exit 0
fi
if [ "$1" = "-s" ]; then # save
  cd $HOME
  for d in $HOME/website/*; do
    git add -f $d/cookies.sqlite
  done
  cd -
  exit 0
fi
# or rather -l
# automation, to confirm login at the other end, if not, use pass entry
# line 1: password, line 2: username, line 3: website URL
# so drive everything from kcpwd/website/x
# and make commands here to set/get/generate/etc :)
# website facebook login
# website facebook rotate # generate new password and login/set
# website facebook purge # clear cache/etc/start over aka rm -rf profile dir :)
# -p gives password
# eventually if ends in .com or .org or .anything then `search` aka command line completion comes here, aka `facebook` just works, etc
# todo include password for $1/website
# check for a TLD like .com or .org and add .com if none as default
if command -v firefox; then
  ff=$(command -v firefox)
elif command -v firefox-esr; then
  ff=firefox-esr
else
  ff=/Applications/Firefox.app/Contents/MacOS/firefox
fi
if [ ! -d "$HOME/website/$1" ]; then
  # if making a dir, then include the password! :p
  mkdir -p $HOME/website/$1
fi
if ! pass -c kcpwd/$1 2>/dev/null; then
  if ! pass -c kcpwd/craig/$1 2>/dev/null; then
    if ! pass -c kcpwd/finances/$1 2>/dev/null; then
      if ! pass -c kcpwd/utilities/$1 2>/dev/null; then
        if ! pass -c kcpwd/ecom/$1 2>/dev/null; then
          echo "no password found, maybe add it!"
        fi
      fi
    fi
  fi
fi
$ff --profile $HOME/website/$1 https://$1  &
