gitnu 0.2.1

gitnu indexes your git status so you can use numbers instead of filenames.
Documentation
#!/usr/bin/env bash

GIT_USER=''
GIT_EMAIL=''
GIT_DEFAULT_BRANCH=''
GIT_STATUS_HINTS=''

gcf() {
  git config --global $@
}

get_git_config() {
  GIT_STATUS_HINTS=$(gcf advice.statusHints 2>&1)
  GIT_USER=$(gcf user.name 2>&1)
  GIT_EMAIL=$(gcf user.email 2>&1)
  GIT_DEFAULT_BRANCH=$(gcf init.defaultBranch 2>&1)
}

set_git_config() {
  [[ $GIT_USER == '' ]] && gcf user.name 'bot'
  [[ $GIT_EMAIL == '' ]] && gcf user.email 'bot@gitnu.co'
  [[ $GIT_DEFAULT_BRANCH == '' ]] && gcf init.defaultBranch 'main'
  gcf advice.statusHints false
}

reset_git_config() {
  ([ $GIT_USER ] && gcf user.name $GIT_USER) || gcf --unset user.name
  ([ $GIT_EMAIL ] && gcf user.email $GIT_EMAIL) || gcf --unset user.email
  ([ $GIT_DEFAULT_BRANCH ] && gcf init.defaultBranch $GIT_DEFAULT_BRANCH) ||
    gcf --unset init.defaultBranch
  ([ $GIT_STATUS_HINTS ] && gcf advice.statusHints $GIT_STATUS_HINTS) ||
    gcf --unset advice.statusHints
}

setup() {
  # navigate to where this script is located
  HERE=$PWD
  GITNU=$HERE/../target/debug/gitnu
  REC_DIR=$HERE/received
  rm -rf $REC_DIR && mkdir $REC_DIR
  get_git_config
  set_git_config
}

get_test_id() {
  local N=${1##*/} && printf ${N%%.*}
}

get_test_title() {
  local title="$(head -n 1 $1)" && printf "${title### }"
}

assert() {
  if [[ "$1" != "$2" ]]; then
    echo "expected: $1"
    echo "received: $2"
    exit 1
  fi
}

cleanup() {
  reset_git_config
  assert $PWD $HERE
  rm -rf $HERE/tmp
}

_pushd() { # silent pushd
  pushd $1 >/dev/null
}

_popd() { # silent popd
  popd >/dev/null
}

_git() { # silent git
  git $@ >/dev/null
}

_gitnu() { # silent gitnu
  $GITNU $@ >/dev/null
}

gitnu() { # gitnu
  $GITNU $@
}

# $1 : test file
# $2 : test title
pass() {
  printf "\033[0;30m\033[1;42m PASS \033[1;0m $1 \033[0;37m$2\033[1;0m\n"
}

# $1 : test file
# $2 : test title
fail() {
  printf "\033[0;30m\033[1;41m FAIL \033[1;0m $1 \033[0;37m$2\033[1;0m\n"
}

# $1 : test file
# $2 : missing required file
not_found() {
  printf "\033[0;30m\033[1;41m FAIL \033[1;0m $1 \033[0;33m($2 not found)\033[1;0m\n"
}