mirror of https://github.com/garrytan/gstack.git
Merge d23b219444 into a3259400a3
This commit is contained in:
commit
263c47257e
|
|
@ -54,9 +54,9 @@ Ask the user which directory to restrict edits to. Use AskUserQuestion:
|
|||
|
||||
Once the user provides a directory path:
|
||||
|
||||
1. Resolve it to an absolute path:
|
||||
1. Resolve it to an absolute path (including symlinks):
|
||||
```bash
|
||||
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd)
|
||||
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd -P)
|
||||
echo "$FREEZE_DIR"
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ Ask the user which directory to restrict edits to. Use AskUserQuestion:
|
|||
|
||||
Once the user provides a directory path:
|
||||
|
||||
1. Resolve it to an absolute path:
|
||||
1. Resolve it to an absolute path (including symlinks):
|
||||
```bash
|
||||
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd)
|
||||
FREEZE_DIR=$(cd "<user-provided-path>" 2>/dev/null && pwd -P)
|
||||
echo "$FREEZE_DIR"
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -52,11 +52,26 @@ esac
|
|||
FILE_PATH=$(printf '%s' "$FILE_PATH" | sed 's|/\+|/|g;s|/$||')
|
||||
|
||||
# Resolve symlinks and .. sequences (POSIX-portable, works on macOS)
|
||||
# For directories (like FREEZE_DIR), cd into them and use pwd -P.
|
||||
# For files, resolve the parent directory and append the basename.
|
||||
_resolve_path() {
|
||||
local _input="$1"
|
||||
|
||||
# If it's a directory, cd into it and resolve with pwd -P
|
||||
if [ -d "$_input" ]; then
|
||||
cd "$_input" 2>/dev/null && pwd -P && return 0
|
||||
fi
|
||||
|
||||
# For non-directories or if cd failed, resolve component-by-component
|
||||
local _dir _base
|
||||
_dir="$(dirname "$1")"
|
||||
_base="$(basename "$1")"
|
||||
_dir="$(cd "$_dir" 2>/dev/null && pwd -P || printf '%s' "$_dir")"
|
||||
_dir="$(dirname "$_input")"
|
||||
_base="$(basename "$_input")"
|
||||
|
||||
# If the parent directory exists and is accessible, resolve it
|
||||
if [ -d "$_dir" ]; then
|
||||
_dir="$(cd "$_dir" 2>/dev/null && pwd -P || printf '%s' "$_dir")"
|
||||
fi
|
||||
|
||||
printf '%s/%s' "$_dir" "$_base"
|
||||
}
|
||||
FILE_PATH=$(_resolve_path "$FILE_PATH")
|
||||
|
|
|
|||
Loading…
Reference in New Issue