From 285220820eb842b4dfe52c19852bf71fca517c74 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 25 Mar 2024 17:00:26 -0700 Subject: cd: when using alias or number, print new PWD. * cdlog.sh (cdlog.chdir): New local variale print indicates whether we should print the new $PWD after a successful cd. We set this when resolving a numeric argument, or cdalias. Some other commands already print. The purpose of this to leave a visible trail in the terminal confirming where the directory was change, for those users who don't have the directory in the shell prompt. Note that "cd -" in Bash has this behavior built in: it prints the path, for the same reason we are doing. --- cdlog.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cdlog.sh b/cdlog.sh index 1b061fb..e5a6aae 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -157,6 +157,7 @@ cdlog.chdir() { local cur=$PWD local def + local print= declare -n d=cdlog_hist if [ $# -eq 2 -a "$1" = -P ] ; then @@ -165,11 +166,13 @@ cdlog.chdir() ;; ( [1-9] ) set -- -P "${d[$2]}" + print=y ;; ( ?* ) def=${cdlog_alias[$2]} if [ -n "$def" ] ; then - set -- -P "$def" + set -- -P "$def" + print=y fi ;; ( * ) @@ -181,6 +184,7 @@ cdlog.chdir() if command cd "$@" && [ "$PWD" != "$cur" ]; then # only if we successfully change to a different # directory do the following + [ $print ] && printf "%s\n" "$PWD" if [ $cdlog_lru ] ; then local nx= -- cgit v1.2.3