Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: HOW TO distiguish between command input and forked subshell ?



On Sep 7,  6:30pm, C. v. Stuckrad wrote:
} Subject: HOW TO distiguish between command input and forked subshell ?
}
} The User who aked was a typical beginner, who used a macro/function
}    chpwd () { ...to change x-window-title to the current dir... }
} and now the title is no longer changed by cd-ing inside of $()
} expansions. BUT if you just type '(cd somwhere; do_something)'
} you again get the title changed to 'somewhere' instead of staying
} where the zsh stood and stayed !

Don't change the title bar in chpwd().  Change the title bar in precmd().
If you want to avoid changing it "too frequently" for some reason, use

	if [[ ${oldPWD:=.} != $PWD ]]
	then
	    # ... change title bar and ...
	    oldPWD=$PWD
	fi

} Does somebody see a chance to distinguish the two cases ?
} I first thought $SHLVL, but it stays the same!

In older Bourne shells you used to be able to distinguish by using

	foo=$$; (if [ $$ -ne $foo ] ... ; )

because $$ would change inside the subshell.  But zsh doesn't do a new
getpid() for every $$ reference, so that doesn't work.  (This causes
other problems, because you used to be able to have a subshell kill
itself with `kill -1 $$` but in zsh that kills the parent.)

I don't know of any way to detect subshell-ness, having played with
it a bit in the past.



-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



Messages sorted by: Reverse Date, Date, Thread, Author