xref: /titanic_44/usr/src/lib/libshell/common/fun/title (revision 01335b0d1c4e0c0f16325a830b24ea2a4076fd38)
1# add to (+), delete from (-), set [=], or print (.) window title
2# arguments are eval'd before printing
3# title text string exported in TITLE_TEXT
4
5function title # [ + | - | = | . ] title ...
6{
7	typeset	x t="$TITLE_TEXT"
8
9	case $1 in
10	+)	shift
11		case $# in
12		0)	;;
13		*)	for x
14			do	case " $t " in
15				*" $x "*)	;;
16				"  ")		t=$x ;;
17				*)		t="$t $x" ;;
18				esac
19			done
20			case $t in
21			$TITLE_TEXT)	return 1 ;;
22			esac
23			;;
24		esac
25		;;
26	-)	shift
27		case $# in
28		0)	;;
29		*)	for x
30			do	case " $t " in
31				*" $x "*)	t="${t%?( )$x*}${t##*$x?( )}" ;;
32				esac
33			done
34			case $t in
35			$TITLE_TEXT)	return 1 ;;
36			esac
37			;;
38		esac
39		;;
40	.)	print -r -- "$TITLE_TEXT"
41		return 0
42		;;
43	=)	shift
44		t="$*"
45		;;
46	*)	t="$*"
47		;;
48	esac
49	export TITLE_TEXT="$t"
50	eval x=\"$t\"
51	case $TERM in
52	630*)			print -nr -- $'\E[?'"${#x}"$';0v'"${x}" ;;
53	uwin*|*vt100|xterm*)	print -nr -- $'\E]0;'"${x}"$'\a' ;;
54	*)			return 1 ;;
55	esac
56	return 0
57}
58