Revision 9244
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
237 | 237 |
|
238 | 238 |
#### paths |
239 | 239 |
|
240 |
canon_rel_path()
|
|
240 |
rel_path() # usage: base_dir=... path=... rel_path
|
|
241 | 241 |
{ |
242 |
local path="$1" |
|
243 |
path="$(realpath "$path")" # canonicalize |
|
244 |
path="${path#$(pwd -P)/}" # remove any shared prefix with the current dir |
|
242 |
log++; kw_params base_dir path |
|
243 |
: "${base_dir:?}" "${path:?}" |
|
244 |
|
|
245 |
path="${path#$base_dir/}" # remove any prefix shared with base_dir |
|
246 |
|
|
247 |
echo_vars path |
|
245 | 248 |
echo "$path" |
246 | 249 |
} |
247 | 250 |
|
251 |
canon_rel_path() { base_dir="$(pwd -P)" path="$(realpath "$1")" rel_path; } |
|
252 |
|
|
248 | 253 |
# makes $1 a canon_rel_path if it's a filesystem path |
249 | 254 |
alias cmd2rel_path="$(cat <<'EOF' |
250 | 255 |
if test "$(type -t "$1")" = file && test -e "$1"; then # not relative to PATH |
Also available in: Unified diff
lib/sh/util.sh: split canon_rel_path() into itself and rel_path() helper for clarity