summary refs log tree commit diff
path: root/tools/bin/__dispatch.sh
blob: 7db75bf870f3df3b69d9c35c15cbe8c9d02214ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# This script dispatches invocations transparently to programs instantiated from
# Nix.
#
# To add a new tool, in
set -ueo pipefail

readonly REPO_ROOT=$(git rev-parse --show-toplevel)
readonly ARGS="$@"
readonly TARGET_TOOL=$(basename $0)

function nix_dispatch() {
  local attr="${1}"
  local result=$(nix-build --no-out-link --attr "${attr}" "${REPO_ROOT}")

  PATH="${result}/bin:$PATH"
  if [ -z "${ARGS}" ]; then
    exec "${TARGET_TOOL}"
  else
    exec "${TARGET_TOOL}" "${ARGS}"
  fi
}

case "${TARGET_TOOL}" in
  git-appraise)
    nix_dispatch "thirdParty.gitAppraise"
    ;;
  *)
    echo "The tool '${TARGET_TOOL}' is currently not installed in this repository."
    ;;
esac