]> www.wagner.pp.ru Git - sites/home_page.git/blob - software/unix/xtitle.sh
f9b0c75d9de02fc91f2bb0132f7a77ca868be644
[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=4 ;# 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 }
17 # tries to get tty name from command name
18 get_tty_from_command () {
19   local t
20   echo \"$cmdcolumn\" \"$ttycolumn\"
21   t=`ps $psargs|awk "\\$$cmdcolumn~/$1/ {print \"$ttyprefix\" \\$$ttycolumn;exit}"`
22   if [ -z "$t" ]
23      then
24        echo "None of your processes matches pattern \"$1\"" >&2
25        exit 1
26      fi
27   check_tty $t
28 }
29 # checks if supplied tty name is valid device name
30 check_tty () {
31   if [ ! -c $1 ] 
32      then
33        echo "$i is not valid tty name" >&2
34        exit 1
35      fi
36   if [ ! -w $1 ]
37      then
38        echo "$i is not writable for you" >&2
39        exit 1
40      fi
41   tty=$1
42 }
43 # by default change our own xterm title
44 tty=`tty`
45 # by default change both window name and icon name
46 mode=0
47 set -- `getopt "iwfc:t:h" $*`
48 if [ $? != 0 ]
49 then
50  usage
51  echo Invalid options. Usage: >&2
52  exit 1
53 fi
54 for i
55 do
56        case $i
57        in 
58           -i) mode=1;shift;;
59           -w) mode=2;shift;;
60           -f) mode=50;shift ;;
61           -t) check_tty $2;shift;shift;;
62           -c) get_tty_from_command $2;shift;shift;;
63           -h) echo "$0: changes a title of xterm window" 
64               usage 
65               exit 0 
66              ;;
67           --) shift; break;;
68        esac
69        
70 done
71 echo -e "\\033]$mode;$*\a\c" >$tty 
72