#!/bin/bash

[[ -n ${ZSH_VERSION-} ]] &&
  GIT_NESTED_ROOT=$0 ||
  GIT_NESTED_ROOT=$BASH_SOURCE

[[ $GIT_NESTED_ROOT =~ ^/ ]] ||
  GIT_NESTED_ROOT=$PWD/$GIT_NESTED_ROOT

GIT_NESTED_ROOT=$(
  cd "$(dirname "$GIT_NESTED_ROOT")" || return
  pwd
) || return

export GIT_NESTED_ROOT
export PATH=$GIT_NESTED_ROOT/bin:$PATH
export MANPATH=$GIT_NESTED_ROOT/man:$MANPATH

# Tab completion. The script is generated by git-nested itself, from the
# same tables the argument parser is built from, so it can never drift.
if [[ -n ${ZSH_VERSION-} ]]; then
  eval "$(git-nested completion zsh)"
else
  eval "$(git-nested completion bash)"
fi
