Skip to content

Commit

Permalink
refactor: improve fs_* (#99)
Browse files Browse the repository at this point in the history
improve `_guard_path` to use `realpath -m <path>` to get absolute path
  • Loading branch information
sigoden authored Aug 17, 2024
1 parent a53ca4f commit 760ea38
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Argcfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ version() {
fi
argc --argc-version
jq --version
ls --version 2>&1 | head -n 1
for item in "${LANG_CMDS[@]}"; do
cmd="${item#*:}"
if [[ "$cmd" == "bash" ]]; then
Expand Down
3 changes: 2 additions & 1 deletion agents/coder/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
# @option --contents! The contents of the file
fs_create() {
_guard_path "$argc_path" Create
mkdir -p "$(dirname "$argc_path")"
printf "%s" "$argc_contents" > "$argc_path"
echo "File created: $argc_path" >> "$LLM_OUTPUT"
}
Expand Down Expand Up @@ -44,7 +45,7 @@ fs_edit() {
}

_guard_path() {
path="$(realpath "$1")"
path="$(realpath -m "$1")"
action="$2"
if [[ ! "$path" == "$(pwd)"* ]]; then
if [ -t 1 ]; then
Expand Down
2 changes: 1 addition & 1 deletion tools/fs_rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main() {
}

_guard_path() {
path="$(realpath "$1")"
path="$(realpath -m "$1")"
action="$2"
if [[ ! "$path" == "$(pwd)"* ]]; then
if [ -t 1 ]; then
Expand Down
2 changes: 1 addition & 1 deletion tools/fs_write.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ main() {
}

_guard_path() {
path="$(realpath "$1")"
path="$(realpath -m "$1")"
action="$2"
if [[ ! "$path" == "$(pwd)"* ]]; then
if [ -t 1 ]; then
Expand Down

0 comments on commit 760ea38

Please sign in to comment.