Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for debug env variable #12

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions nix-watch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand Down Expand Up @@ -191,20 +202,22 @@ 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
IGNORE_PATTERNS=()
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
Expand Down