: etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;;
:
: "  @(#)$Id: SetTandCTTY,v 1.3 2018/12/15 22:28:21 jneitzel Exp $  "
:
: "  The author of this file, J.A. Neitzel <jan (at) etsh (dot) nl>,  "
: "  hereby grants it to the public domain.                           "
:

:
: "  Set $T and/or setenv CTTY as needed.  "
:
: "  usage: source [/path/to/]SetTandCTTY  "
: "     or:                                "
: "  usage: .      [/path/to/]SetTandCTTY  "
:

: " Ensure we have a usable ETSHDIR ($d). "
fd2 -ef/dev/null etshdir
if $? -eq 0 goto Continue
	source etshdir $$
	if $? -eq 0 goto Continue
		fd2 -e echo "$0: Error!" ; false ; exit
	: fallthrough

: Continue
	set S 0
	printenv CTTY | wc -l | tr -d ' ' | grep '^1$' >/dev/null
	if $? -ne 0 goto NoCtty
		( \
		   echo -n 'set T "' ; printenv CTTY | tr -d '\n' ; echo '"' \
		) >$d/TisCTTY
		source $d/TisCTTY
		set S 1
		rm $d/TisCTTY
		: fallthrough
	: NoCtty
		if $S -eq 1 goto TisCTTY
			setenv CTTY $t
			set    T    $t
		: TisCTTY
			: fallthrough
	unset S

: Done - " zero status (true) "
