#!/bin/sh

basedir=$(dirname "$_")
basedir=$(cd "$basedir" && pwd)

export ANSIBLE_CONFIG=$basedir/ansible/ansible.cfg

echo "Adding bin/ to path"
PATH="$basedir/bin:$PATH"

#echo "Adding bin/.tmp/asdf-data/shims/ to path"
#PATH="$basedir/bin/.tmp/asdf-data/shims:$PATH"

if [[ ! -r .vault ]]
then
  echo "Missing .vault"
else
  echo "Loading secrets"
  source <(ansible-vault view $basedir/.vault)
fi

if [[ -x $basedir/ansible/.vault-password ]]
then
  export ANSIBLE_VAULT_PASS=$($basedir/ansible/.vault-password)
fi

if [[ -d $basedir/bin/.mc ]]
then
  echo "Loading completions for mc"
  complete -C $basedir/bin/mc mc
fi