From eb1f380710b595b2416145cba81ba407f83666d2 Mon Sep 17 00:00:00 2001 From: andrewvious Date: Wed, 7 Aug 2024 13:24:35 -0500 Subject: [PATCH 1/2] add support for debug env variable --- flake.nix | 1 + nix-watch.nix | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 4cc49c3..fc8c4bc 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,7 @@ nil nixpkgs-fmt ] ++ nix-watch.devTools; + NIX_WATCH_DEBUG=true; }; formatter = pkgs.nixpkgs-fmt; }); diff --git a/nix-watch.nix b/nix-watch.nix index fb7d70e..e78363d 100644 --- a/nix-watch.nix +++ b/nix-watch.nix @@ -77,6 +77,17 @@ let done COMMAND=("''${processed_command[@]}") } + convert_int_to_bool() { + local maybe_int="$1" + + if [[ "$maybe_int" == 0 ]]; then + ${echo} false + elif [[ "$maybe_int" == 1 ]]; then + ${echo} true + else + ${echo} "$maybe_int" + fi + } # Initialize variables with default values COMMAND=() @@ -191,8 +202,12 @@ let fi debug "Command: ''${ANSI_BLUE}''${COMMAND[*]}''${ANSI_RESET}" - # Resolve the watch directory to its absolute path + # Resolve the watch directory to its absolute path and ensure it exists WATCH_DIR=$(realpath "$WATCH_DIR") + if [ ! -d "$WATCH_DIR" ]; then + error "Directory '$WATCH_DIR' does not exist." + exit 1 + fi debug "Watching directory: ''${ANSI_BLUE}$WATCH_DIR''${ANSI_RESET}" if [ "$IGNORE_NOTHING" == true ]; then @@ -200,11 +215,9 @@ let fi ignore_patterns="[''${IGNORE_PATTERNS[@]}]" debug "The following patterns will be ignored: ''${ANSI_BLUE}$ignore_patterns''${ANSI_RESET}" - - # Ensure the directory exists - if [ ! -d "$WATCH_DIR" ]; then - error "Directory '$WATCH_DIR' does not exist." - exit 1 + + if [[ "$DEBUG" == false && -n "$NIX_WATCH_DEBUG" ]]; then + DEBUG=$(convert_int_to_bool $NIX_WATCH_DEBUG) fi # Temporary file to store the PID of the running command From 25d84d61c369161d8a61d0fe7d3fbd6ae6831730 Mon Sep 17 00:00:00 2001 From: andrewvious Date: Wed, 7 Aug 2024 13:30:35 -0500 Subject: [PATCH 2/2] rm debug env var from flake.nix --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index fc8c4bc..4cc49c3 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,6 @@ nil nixpkgs-fmt ] ++ nix-watch.devTools; - NIX_WATCH_DEBUG=true; }; formatter = pkgs.nixpkgs-fmt; });