72ba099b8a20d699c176e4656203277b6690c1d4
[platform/upstream/bash.git] / examples / scripts / xterm_title
1 #! /bin/bash
2 #
3 # xterm_title - print the contents of the xterm title bar
4 #
5 # Derived from http://www.clark.net/pub/dickey/xterm/xterm.faq.html#how2_title
6 #
7 P=${0##*/}
8 [ -z "$DISPLAY" ] && {
9         echo "${P}: not running X" >&2
10         exit 1
11 }
12
13 if [ -z "$TERM" ] || [ "$TERM" != "xterm" ]; then
14         echo "${P}: not running in an xterm" >&2
15         exit 1
16 fi
17
18 exec </dev/tty
19 old=$(stty -g)
20 stty raw -echo min 0  time ${1-10}
21 echo -e "\033[21t\c" > /dev/tty
22 IFS='' read -r a
23 stty $old
24 b=${a#???}
25 echo "${b%??}"
26
27 exit 0