Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/docs/ksh/functions/title.txt
1798 views
1
# add to (+), delete from (-), print (.), or set ([=]) window title
2
# arguments are eval'd before printing
3
# title text string exported in TITLE_TEXT
4
5
function 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
*) t="$*"
44
;;
45
esac
46
export TITLE_TEXT="$t"
47
eval x=\"$t\"
48
case $TERM in
49
630*) print -nr -- "[?${#x};0v$x" ;;
50
vt100|xterm*) print -nr -- "]0;$x" ;;
51
*) return 1 ;;
52
esac
53
return 0
54
}
55
56