use-grealpath
Original:🇺🇸 English
Translated
Enforces using grealpath command for relative path calculations and absolute path conversions. Use when calculating relative paths between files, converting relative paths to absolute paths, or working with file path operations.
6installs
Added on
NPX Install
npx skill4agent add totto2727-dotfiles/agents use-grealpathTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Use grealpath for Path Operations
Rule (CRITICAL)
ALWAYS use command for:
grealpath- Calculating relative paths between files/directories
- Converting relative paths to absolute paths
- Resolving symbolic links to absolute paths
Relative Path Calculation
Use to calculate relative paths:
grealpath --relative-to=<base>bash
# Calculate relative path from base directory to target
grealpath --relative-to=/home/user /home/user/test
# Output: test
# Calculate relative path from current directory
grealpath --relative-to=. ./subdir/file.txt
# Output: subdir/file.txt
# Calculate relative path between two specific paths
grealpath --relative-to=/path/to/base /path/to/base/subdir/file.txt
# Output: subdir/file.txtAbsolute Path Conversion
Use to convert relative paths to absolute paths:
grealpathbash
# Convert relative path to absolute path
grealpath ./subdir/file.txt
# Output: /home/user/project/subdir/file.txt
# Convert with current directory as base
grealpath file.txt
# Output: /home/user/project/file.txt
# Resolve symbolic links to absolute paths
grealpath symlink
# Output: /home/user/project/actual/pathCommon Use Cases
Getting Relative Path Between Two Files
bash
# From file A to file B
grealpath --relative-to=/path/to/fileA /path/to/fileBConverting Relative to Absolute
bash
# Simple conversion
grealpath relative/path/to/file
# With base directory
grealpath --relative-to=/base/dir relative/pathResolving Paths with Symbolic Links
bash
# Resolve all symbolic links
grealpath -s symlink
# Or without -s flag (default behavior resolves symlinks)
grealpath symlinkExamples
Good: Using grealpath
bash
# Calculate relative path
grealpath --relative-to=/home/user /home/user/project/src/file.ts
# Output: project/src/file.ts
# Convert to absolute path
grealpath ./src/file.ts
# Output: /home/user/project/src/file.ts
# Resolve symbolic link
grealpath ./link-to-file
# Output: /home/user/project/actual/file.tsBad: Manual Path Manipulation
bash
# DO NOT manually calculate relative paths
# DO NOT use cd and pwd combinations
# DO NOT use string manipulation for pathsNotes
- is the GNU version of
grealpath(Mac uses BSD version by default)realpath - Always use instead of
grealpathfor consistent behaviorrealpath - The option requires GNU coreutils
--relative-to - Paths are normalized (removes and
.components)..