#!/bin/sh - xrlogin=xt # makehostmenus - generate and insert customized host menus into a .twmrc file # Steve Kinzler, kinzler@cs.indiana.edu, Feb 94 # http://www.cs.indiana.edu/~kinzler/home.html#x11 append=; bad= file="${TWMRC-$HOME/.twmrc}" string='# DO NOT DELETE THIS LINE -- makehostmenus depends on it' while : do case $# in 0) break;; *) case "$1" in -a) append=t;; -f) shift; file="$1";; -s) shift; string="$1";; -h) bad=t; break;; -*) bad=t; echo "$0: unknown option ($1)" 1>&2;; *) bad=t; break;; esac shift;; esac done case "$bad" in ?*) cat << EOF 1>&2 usage: $0 [ -a ] [ -f file ] [ -s string ] -a append host menus to file (default replace) -f modify the given file (default ${TWMRC-$HOME/.twmrc}) -s recognize and use the given delimiter string in the file EOF exit 1;; esac tmp="$file"~ trap "rm -f $tmp; exit" 0 1 2 13 15 case "$append" in ?*) cat < "$file";; *) delim=`echo "$string" | sed 's/[$*.[\\\\^]/\\\\&/g'` sed "/^$delim$/,\$d" < "$file";; esac > $tmp || exit 2 ( cat << EOF $string # Generated by makehostmenus menu "MyHosts" { "My Hosts" f.title EOF hosts | awk '{ printf "\t\"%-23s!\"%s %s &\"\n", $0 "\"", "'"$xrlogin"'", $0 }' cat <<'EOF' } menu "Hostlists" { "Hostlists" f.title "unix" ("white":"blue") f.menu "Hostlist unix" # "foreign" ("white":"blue") f.menu "Hostlist foreign" } EOF hostlist -ms unix 2> /dev/null | #foreign | sed 's/ !"xrlogin / !"'"$xrlogin"' / s/ f.menu / ("white":"blue") f.menu /' ) >> $tmp cmp $tmp "$file" > /dev/null 2>&1 && exit test -s $tmp && cat < $tmp > "$file"