diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/execute_command.sh | 10 | ||||
| -rwxr-xr-x | tools/execute_sql_code.sh | 10 | ||||
| -rwxr-xr-x | tools/fs_patch.sh | 14 | ||||
| -rwxr-xr-x | tools/fs_rm.sh | 18 | ||||
| -rwxr-xr-x | tools/fs_write.sh | 18 | ||||
| -rwxr-xr-x | tools/search_wikipedia.sh | 2 | ||||
| -rwxr-xr-x | tools/send_twilio.sh | 4 |
7 files changed, 19 insertions, 57 deletions
diff --git a/tools/execute_command.sh b/tools/execute_command.sh index b263b10..eb58eba 100755 --- a/tools/execute_command.sh +++ b/tools/execute_command.sh @@ -6,14 +6,10 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { - if [ -t 1 ]; then - read -r -p "Are you sure you want to continue? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi + "$ROOT_DIR/utils/guard_operation.sh" eval "$argc_command" >> "$LLM_OUTPUT" } diff --git a/tools/execute_sql_code.sh b/tools/execute_sql_code.sh index df57dea..34cd948 100755 --- a/tools/execute_sql_code.sh +++ b/tools/execute_sql_code.sh @@ -9,15 +9,11 @@ set -e # @env USQL_DSN! The database url, e.g. pgsql://user:pass@host/dbname # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { if ! grep -qi '^select' <<<"$argc_code"; then - if [ -t 1 ]; then - read -r -p "Are you sure you want to continue? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi + "$ROOT_DIR/utils/guard_operation.sh" fi usql -c "$argc_code" "$USQL_DSN" >> "$LLM_OUTPUT" } diff --git a/tools/fs_patch.sh b/tools/fs_patch.sh index 14e46d2..ce71628 100755 --- a/tools/fs_patch.sh +++ b/tools/fs_patch.sh @@ -18,22 +18,16 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { if [ ! -f "$argc_path" ]; then echo "Not found file: $argc_path" exit 1 fi - root_dir="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" - new_contents="$(awk -f "$root_dir/utils/patch.awk" "$argc_path" <(printf "%s" "$argc_contents"))" + new_contents="$(awk -f "$ROOT_DIR/utils/patch.awk" "$argc_path" <(printf "%s" "$argc_contents"))" printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true - if [ -t 1 ]; then - echo - read -r -p "Apply changes? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi + "$ROOT_DIR/utils/guard_operation.sh" "Apply changes?" printf "%s" "$new_contents" > "$argc_path" echo "The patch applied to: $argc_path" >> "$LLM_OUTPUT" diff --git a/tools/fs_rm.sh b/tools/fs_rm.sh index dd1e2f7..9d9386f 100755 --- a/tools/fs_rm.sh +++ b/tools/fs_rm.sh @@ -7,26 +7,14 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { if [[ -f "$argc_path" ]]; then - _guard_path "$argc_path" Remove + "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Remove '$argc_path'?" rm -rf "$argc_path" fi echo "Path removed: $argc_path" >> "$LLM_OUTPUT" } -_guard_path() { - path="$(realpath -m "$1")" - action="$2" - if [[ ! "$path" == "$(pwd)"* ]]; then - if [ -t 1 ]; then - read -r -p "$action $path? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi - fi -} - eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fs_write.sh b/tools/fs_write.sh index 0e0dba0..303a77b 100755 --- a/tools/fs_write.sh +++ b/tools/fs_write.sh @@ -8,25 +8,13 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + main() { - _guard_path "$argc_path" Write + "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Write '$argc_path'?" mkdir -p "$(dirname "$argc_path")" printf "%s" "$argc_contents" > "$argc_path" echo "The contents written to: $argc_path" >> "$LLM_OUTPUT" } -_guard_path() { - path="$(realpath -m "$1")" - action="$2" - if [[ ! "$path" == "$(pwd)"* ]]; then - if [ -t 1 ]; then - read -r -p "$action $path? [Y/n] " ans - if [[ "$ans" == "N" || "$ans" == "n" ]]; then - echo "Aborted!" - exit 1 - fi - fi - fi -} - eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/search_wikipedia.sh b/tools/search_wikipedia.sh index 0bf791e..6c7010d 100755 --- a/tools/search_wikipedia.sh +++ b/tools/search_wikipedia.sh @@ -17,7 +17,7 @@ main() { title="$(echo "$json" | jq -r '.query.search[0].title // empty')" pageid="$(echo "$json" | jq -r '.query.search[0].pageid // empty')" if [[ -z "$title" || -z "$pageid" ]]; then - echo "Error: No results found for '$argc_query'" + echo "error: no results for '$argc_query'" >&2 exit 1 fi title="$(echo "$title" | tr ' ' '_')" diff --git a/tools/send_twilio.sh b/tools/send_twilio.sh index 2a197ff..0259efb 100755 --- a/tools/send_twilio.sh +++ b/tools/send_twilio.sh @@ -31,10 +31,10 @@ main() { if [[ "$(echo "$body" | jq -r 'has("sid")')" == "true" ]]; then echo "Message sent successfully" >> "$LLM_OUTPUT" else - _die "$body" + _die "error: $body" fi else - _die "$body" + _die "error: $body" fi } |
