From 2e5964514a8bf686fce95b90ec5099fc818ebd95 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 10 May 2021 19:48:05 +0200 Subject: [PATCH] chore(develop): prevent multiple develop --- shell.nix | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/shell.nix b/shell.nix index c7b843a79..ee1664f66 100644 --- a/shell.nix +++ b/shell.nix @@ -16,7 +16,19 @@ let ''; develop = pkgs.writeScriptBin "develop" '' - #!${pkgs.zsh}/bin/zsh + #!${pkgs.zsh}/bin/zsh -e + + basePath=$(pwd) + exec 4<>''${basePath}/.develop.env + + flockRes= + set +e + ${pkgs.util-linux}/bin/flock -en 4; flockRes=$? + set -e + if [[ ''${flockRes} -ne 0 ]]; then + echo "Could not take exclusive lock; is another develop running?" >&2 + exit ''${flockRes} + fi cleanup() { set +e -x @@ -32,10 +44,6 @@ let trap cleanup EXIT - basePath=$(pwd) - - echo "" > ''${basePath}/.develop.env - export PORT_OFFSET=$(((16#$(whoami | sha256sum | head -c 16)) % 1000)) if [[ -z "$PGHOST" ]]; then @@ -140,7 +148,7 @@ let set -xe - cat >> ''${basePath}/.develop.env <&4 <