#!/usr/bin/env bash
# reset environment variables that could interfere with normal usage
export GREP_OPTIONS=
# put all utility functions here

# make a temporary file
git_extra_mktemp() {
    mktemp -t "$(basename "$0")".XXX
}


VERSION="3.0.0"

update() {
  local bin=$(which git-extras)
  local prefix=${bin%/*/*}
  local orig=$PWD

  cd /tmp \
    && rm -fr ./git-extras \
    && git clone --depth 1 https://github.com/tj/git-extras.git \
    && cd git-extras \
    && PREFIX="$prefix" make install \
    && cd "$orig" \
    && echo "... updated git-extras $VERSION -> $(git extras --version)"
}

case "$1" in
  -v|--version)
    echo $VERSION && exit 0
    ;;
  update)
    update
    ;;
  *)
    man git-extras
    ;;
esac
