refactor: improve fs_* (#99)
improve `_guard_path` to use `realpath -m <path>` to get absolute path
This commit is contained in:
@@ -502,6 +502,7 @@ version() {
|
|||||||
fi
|
fi
|
||||||
argc --argc-version
|
argc --argc-version
|
||||||
jq --version
|
jq --version
|
||||||
|
ls --version 2>&1 | head -n 1
|
||||||
for item in "${LANG_CMDS[@]}"; do
|
for item in "${LANG_CMDS[@]}"; do
|
||||||
cmd="${item#*:}"
|
cmd="${item#*:}"
|
||||||
if [[ "$cmd" == "bash" ]]; then
|
if [[ "$cmd" == "bash" ]]; then
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ set -e
|
|||||||
# @option --contents! The contents of the file
|
# @option --contents! The contents of the file
|
||||||
fs_create() {
|
fs_create() {
|
||||||
_guard_path "$argc_path" Create
|
_guard_path "$argc_path" Create
|
||||||
|
mkdir -p "$(dirname "$argc_path")"
|
||||||
printf "%s" "$argc_contents" > "$argc_path"
|
printf "%s" "$argc_contents" > "$argc_path"
|
||||||
echo "File created: $argc_path" >> "$LLM_OUTPUT"
|
echo "File created: $argc_path" >> "$LLM_OUTPUT"
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ fs_edit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_guard_path() {
|
_guard_path() {
|
||||||
path="$(realpath "$1")"
|
path="$(realpath -m "$1")"
|
||||||
action="$2"
|
action="$2"
|
||||||
if [[ ! "$path" == "$(pwd)"* ]]; then
|
if [[ ! "$path" == "$(pwd)"* ]]; then
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_guard_path() {
|
_guard_path() {
|
||||||
path="$(realpath "$1")"
|
path="$(realpath -m "$1")"
|
||||||
action="$2"
|
action="$2"
|
||||||
if [[ ! "$path" == "$(pwd)"* ]]; then
|
if [[ ! "$path" == "$(pwd)"* ]]; then
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_guard_path() {
|
_guard_path() {
|
||||||
path="$(realpath "$1")"
|
path="$(realpath -m "$1")"
|
||||||
action="$2"
|
action="$2"
|
||||||
if [[ ! "$path" == "$(pwd)"* ]]; then
|
if [[ ! "$path" == "$(pwd)"* ]]; then
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user