lean4-htt/nix/lean-dev.in
Sebastian Ullrich 2c64441910 chore: Nix: disable dirty Git tree warning & fix lean4-diff-test-file
/cc @leodemoura

Note that you will have to restart Emacs and the "Lean shell" around it for the changes to take effect
2020-11-24 20:05:24 +01:00

39 lines
939 B
Bash

#!@bash@/bin/bash
set -euo pipefail
PATH=@nix@/bin:$PATH
call() {
if [[ $json == 1 ]]; then
$@ 2>&1 | awk '
/{/ { print $0; next }
{
gsub(/"/, "\\\"", $0);
gsub(/\n/, "\\n", $0);
printf "{\"severity\": \"error\", \"pos_line\": 0, \"pos_col\": 0, \"file_name\": \"<stdin>\", \"text\": \"%s\"}\n", $0 }'
else
$@
fi
}
json=0
input=
for p in "$@"; do
[[ "$p" == --json ]] && json=1
[[ "$p" != -* ]] && input="$(realpath "$p")"
done
root="$(dirname "${input:-/}")"
while [[ "$root" != / ]]; do
[ -f "$root/flake.nix" ] && break
root="$(realpath "$root/..")"
done
if [[ "$root" == / ]]; then
call @lean@/bin/lean $@
elif [[ "$input" != "$root@srcDir@/"* ]]; then
call nix run "$root#lean-package" -- $@
else
input="$(realpath --relative-to="$root@srcDir@" "$input")"
input="${input%.lean}"
input="${input//\//.}"
call nix develop "$root#mods.\"$input\"" -c lean $@
fi