Revision 9791
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
408 | 408 |
cd -P . # expand symlinks in $PWD so it matches the output of realpath |
409 | 409 |
# do before setting $top_script_abs so realpath has less symlinks to resolve |
410 | 410 |
|
411 |
canon_rel_path() |
|
411 |
canon_rel_path() # usage: [base_dir=...] canon_rel_path path
|
|
412 | 412 |
{ |
413 |
kw_params base_dir; local base_dir="${base_dir-$PWD}" |
|
414 |
base_dir="$(realpath "$base_dir")" || return |
|
413 | 415 |
local path; path="$(realpath "$1")" || return |
414 |
base_dir="$PWD" rel_path
|
|
416 |
rel_path |
|
415 | 417 |
} |
416 | 418 |
|
417 | 419 |
# makes $1 a canon_rel_path if it's a filesystem path |
Also available in: Unified diff
lib/sh/util.sh: support custom $base_dir, which will be run through realpath() to match $path ($PWD, which was used before, did not need to be realpath'd because it was already absolute)