Files
loki/assets/functions/tools/fs_write.sh

28 lines
846 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# @describe Write the full file contents to a file at the specified path.
# @option --path! The path of the file to write to
# @option --contents! The full contents to write to the file
# @env LLM_OUTPUT=/dev/stdout The output path
PROMPT_UTILS="${LLM_ROOT_DIR:-$(dirname "${BASH_SOURCE[0]}")/..}/functions/utils/prompt-utils.sh"
# shellcheck disable=SC1090
source "$PROMPT_UTILS"
# shellcheck disable=SC2154
main() {
if [[ -f "$argc_path" ]]; then
printf "%s" "$argc_contents" | git diff --no-index "$argc_path" - || true
guard_operation "Apply changes?"
else
guard_path "$argc_path" "Write '$argc_path'?"
mkdir -p "$(dirname "$argc_path")"
fi
printf "%s" "$argc_contents" > "$argc_path"
echo "The File contents were written to: $argc_path" >> "$LLM_OUTPUT"
}