#!/usr/bin/env bash
# shellcheck disable=SC2015
# shellcheck disable=SC1090

GPG_TTY=$(tty)
export GPG_TTY

export SSH_ENV="$HOME/.ssh/environment"
start_agent() {
  echo "Initialising new SSH agent..."
  ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  echo succeeded
  chmod 600 "${SSH_ENV}"
  . "${SSH_ENV}" > /dev/null
  ssh-add
}

[ -f "${SSH_ENV}" ] && {
  . "${SSH_ENV}" > /dev/null
  pgrep ^ssh-agent$ > /dev/null || {
    start_agent
  }
} || start_agent

gpg -q -d "$DOTFILES/bash/debug.gpg"

eval "$(direnv hook bash)"
