]> www.wagner.pp.ru Git - sites/home_page.git/blob - software/unix/xtitle.sh
Added bringup script to xtitle page, added XVKbd russian layout
[sites/home_page.git] / software / unix / xtitle.sh
1 #!/bin/sh
2 # customization parameters
3 #ttyprefix=/dev/tty ;# what to add to ttycolumn's word to obtain valid device
4 ttyprefix=/dev/; #for linux systems with /dev/pts
5 cmdcolumn=5 ;# where to find command in ps output
6 ttycolumn=2 ;# where to find tty name in ps output
7 psargs=aww; 
8 # displays usage information
9 usage () {
10  echo "xtitle [ -t tty|-c command] [-i|-w|-f] title" >&2
11  echo " -t specifies tty associated with xterm to change" >&2
12  echo " -c specifies command running in this xterm" >&2
13  echo " -i notifies, that only icon name should be changed" >&2
14  echo " -w that window name only (default - both)">&2
15  echo " -f changes font instead of title" >&2
16  echo " -r raises/deiconifies window instead of changing title" >&2
17 }
18 # tries to get tty name from command name
19 get_tty_from_command () {
20   local t
21   echo \"$cmdcolumn\" \"$ttycolumn\"
22   t=`ps $psargs|awk "\\$$cmdcolumn~/$1/ {print \"$ttyprefix\" \\$$ttycolumn;exit}"`
23   if [ -z "$t" ]
24      then
25        echo "None of your processes matches pattern \"$1\"" >&2
26        exit 1
27      fi
28   check_tty $t
29 }
30 # checks if supplied tty name is valid device name
31 check_tty () {
32   if [ ! -c $1 ] 
33      then
34        echo "$i is not valid tty name" >&2
35        exit 1
36      fi
37   if [ ! -w $1 ]
38      then
39        echo "$i is not writable for you" >&2
40        exit 1
41      fi
42   tty=$1
43 }
44 # by default change our own xterm title
45 tty=`tty`
46 # by default change both window name and icon name
47 mode=0
48 set -- `getopt "iwrfc:t:h" $*`
49 if [ $? != 0 ]
50 then
51  usage
52  echo Invalid options. Usage: >&2
53  exit 1
54 fi
55 for i
56 do
57        case $i
58        in 
59           -i) mode=1;shift;;
60           -w) mode=2;shift;;
61           -f) mode=50;shift ;;
62           -t) check_tty $2;shift;shift;;
63           -c) get_tty_from_command $2;shift;shift;;
64           -h) echo "$0: changes a title of xterm window" 
65               usage 
66               exit 0 
67              ;;
68                 -r) raise_mode=1; shift;;
69           --) shift; break;;
70        esac
71        
72 done
73 echo "tty=$tty"
74 if [ -n "$raise_mode" ]; then
75         echo -ne "\\033[1t\\033[5t" >$tty
76 fi      
77 echo -e "\\033]$mode;$*\a\c" >$tty 
78