Project

General

Profile

« Previous | Next » 

Revision 14542

lib/sh/util.sh: cd(): support rebasing path vars for the new dir

View differences:

trunk/lib/sh/util.sh
987 987
"$@"
988 988
}
989 989

  
990
cd() # indent is permanent within subshell cd was used in
990
cd() # usage: cd dir [path_var...] # path_vars will be rebased for the new dir
991
# indent is permanent within subshell cd was used in
991 992
{
992 993
	log_local; log++ echo_func
993
	cmd2rel_path; echo_cmd "$FUNCNAME" "$@"
994
	local dir="$1"; shift
995
	
996
	# absolutize path_vars
997
	for path_var in "$@"; do # must happen *before* cd to use correct currdir
998
		set_var "$path_var" "$(realpath "${!path_var}")"
999
	done
1000
	
1001
	# change dir
1002
	cmd2rel_path; echo_cmd "$FUNCNAME" "$dir"
994 1003
	if can_log; then caller_indent; fi
995 1004
	# -P: expand symlinks so $PWD matches the output of realpath
996
	self_builtin -P "$@"
1005
	self_builtin -P "$dir"
997 1006
	
998 1007
	func=realpath clear_cache
999 1008
	set_paths
1009
	
1010
	# re-relativize path_vars
1011
	for path_var in "$@"; do # must happen *after* cd to use correct currdir
1012
		set_var "$path_var" "$(canon_rel_path "${!path_var}")"
1013
	done
1000 1014
}
1001 1015

  
1002 1016
## external commands

Also available in: Unified diff