Project

General

Profile

« Previous | Next » 

Revision 10143

lib/sh/util.sh: added canon_dir_rel_path(), which canonicalizes just the parent dir if the path is a symlink, to leave the symlink itself untouched

View differences:

lib/sh/util.sh
472 472
	rel_path
473 473
}
474 474

  
475
canon_dir_rel_path() # usage: [base_dir=...] canon_dir_rel_path path
476
# if the path is a symlink, just its parent dir will be canonicalized
477
{
478
	kw_params base_dir; local base_dir="${base_dir-$PWD}"
479
	base_dir="$(realpath "$base_dir")" || return
480
	local path; path="$(realpath "$(dirname "$1")")/$(basename "$1")" || return
481
	rel_path
482
}
483

  
475 484
# makes $1 a canon_rel_path if it's a filesystem path
476 485
alias cmd2rel_path="$(cat <<'EOF'
477 486
if test "$(type -t "$1")" = file && test -e "$1"; then # not relative to PATH

Also available in: Unified diff