home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / info / unixtrks.txt < prev    next >
Encoding:
Internet Message Format  |  1989-03-21  |  121.3 KB

  1. From: Nancy Blachman <decvax!decwrl!sun!idi!resonex!nancy@Ucb-Vax.ARPA>
  2. To: net.unix, net.unix-wizards, net.sources
  3. Subject: Actual tricks, shells, csh aliases and the like, 1 of 3
  4. Date: 16 Oct 84 21:20:53 GMT
  5. Organization: Resonex Inc., Sunnyvale, CA
  6.  
  7. > [Know anybody with a GREAT .login or .cshrc?]
  8.  
  9. > I'm interested in collecting the little tricks, shell scripts, awk
  10. > hacks, csh aliases, and such that people have built to make their daily
  11. > life a little easier or more automatic.  Being a fairly new system
  12. > administrator I don't have the big toolbox that years of messing around
  13. > will leave you with.  If you have any hacks you're proud of (or that
  14. > you aren't proud of, but which work anyway), and you're willing to make
  15. > them public, mail them to me.  I'll collect, collate, shuffle, sort,
  16. > munge, judge, select and discard them and then "summarize to the net".
  17.  
  18. This article concentrates on  aliases, and .cshrc and .login files I received
  19. in response to my solicitation. The second article in this series focuses 
  20. shell scripts. The third article centers on C programs and awk scripts.
  21.  
  22. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  23. > Nancy Blachman {allegra,hplabs,ihnp4,sun}!resonex!nancy  (408)720 8600 x37 <
  24. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  25.  
  26. ::::::::::::::
  27. aliases/1
  28. ::::::::::::::
  29. Date: Thu, 13 Sep 84 07:27:35 est
  30. From: ihnp4!pur-ee!davy (Dave Curry)
  31. To: ihnp4!resonex!nancy
  32. Subject: aliases
  33.  
  34. Nancy:
  35.  
  36.     Here's a few handy aliases to put your current working
  37. directory into your prompt:
  38.  
  39. alias cd chdir \!:\* \; set prompt='${cwd}\[!\]\ ' \; setenv CWD '$cwd'
  40. alias pd pushd \!:\* \; set prompt='${cwd}\[!\]\ ' \; setenv CWD '$cwd'
  41. alias pp popd \!:\* \; set prompt='${cwd}\[!\]\ ' \; setenv CWD '$cwd'
  42.  
  43. These put the current directory into the environment also, this is
  44. for an editor used here locally which uses this information.  You can delete
  45. that part if you don't need it.
  46.  
  47. --Dave Curry
  48. ihnp4!pur-ee!davy
  49.  
  50.  
  51.  
  52. ::::::::::::::
  53. aliases/2
  54. ::::::::::::::
  55. From: hplabs!sdcrdcf!sdcsvax!greg (Greg Noel)
  56. Date: Thu, 13 Sep 84 10:57:51 pdt
  57. Return-Address: ucbvax!sdcsvax!greg or Greg@NOSC
  58. Organization: NCR Corporation, Torrey Pines
  59. To: sdcrdcf!hplabs!resonex!nancy
  60. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  61.  
  62. I have three little gems from my bag of tricks that I'd like to show you,
  63. all for the C shell.  The first is an alias for the `pwd' command:
  64.     alias pwd    echo \$cwd
  65. The built-in variable `cwd' always contains the current working directory,
  66. and since `echo' is a built-in command, this is MUCH faster than invoking
  67. a program to calculate the actual location.  The only problem (and I don't
  68. have a solution) is that it gets confused by symbolic links to directories.
  69.  
  70. The second one is something that turns the directory structure from something
  71. passive into something active:
  72.     alias come    if -e .greg_come source .greg_come
  73.     alias go    if -e .greg_go   source .greg_go
  74.     alias cd    go \; set prev = \$cwd \; chdir \!\* \; \
  75.                 echo \$prev ==\\\> \$cwd \; come
  76. What this does is cause the shell to look for a specific file whenever it
  77. transfers into a directory, and if it is there, source it.  Also, whenever
  78. you leave a directory, it looks for a different file and sources that before
  79. leaving.  I use this to set up location-specific aliases or to have something
  80. happen auto-magicly whenever I work in some diretory -- for example, changing
  81. into my `play' directory invokes a menu that will set up the environment and
  82. run game programs -- different save files for `rogue' or other stuff that
  83. I don't want to carry around with me all the time.  It's more flexible than
  84. it seems at first glance; the only thing I can suggest is to try it and you
  85. will keep finding new ways to use it.
  86.  
  87. The last one is really a replacement for the `pushd' and `popd' commands --
  88. I didn't like the way they worked, so I did these.  It seperates the action
  89. of pushing a directory from the action of changing directories.  I wanted
  90. this since I also have a whole bunch of aliases to move between widely-
  91. seperated portions of the filesystem (something I do a lot) and it was
  92. easier for me to type `push; u test' (which pushes the current directory
  93. and takes me into the `test' subdirectory of something interesting) than
  94. to type `pushd /long/complicated/path/test'.  This isn't terribly original,
  95. but the gem, and something I find VERY useful is the `back' command, which
  96. takes you to the directory you last left, so you can bouce back and forth
  97. between two directories -- one is the source location and one the test
  98. location, for example.  Anyway, here's what it looks like:
  99.     alias push    set dirstack = \( \$cwd \$dirstack \) \; \
  100.                 echo Pushing \\\[\$\#dirstack] \$cwd \; \!\*
  101.     alias pop    cd \$dirstack\[1] \; set dirstack = \( \$dirstack\[2-] \)
  102.     alias back    set dirstack = \( \$prev \$dirstack \) \; pop
  103.     alias pp    set x = \$dirstack\[1] dirstack\[1] = \$cwd \; cd \$x
  104. Notice that it interacts with the previous alias for `cd' in that it expects
  105. the variable `prev' to have the previous directory (which is what `cd' leaves
  106. in it).  The `pp' alias is sometimes useful -- it pushes the current directory
  107. while transfering to the old top of stack, a simultaneous push-pop.
  108.  
  109. I hope you found these interesting and entertaining.
  110.  
  111. -- Greg Noel, NCR Torrey Pines       Greg@sdcsvax.UUCP or Greg@nosc.ARPA
  112.  
  113. ::::::::::::::
  114. cshrc/1
  115. ::::::::::::::
  116. From: <hplabs!tektronix!jerryp>
  117. Date: Thursday, 13 Sep 84 09:48:55 PDT
  118. To: resonex!nancy, jerryp
  119. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  120.  
  121. Nancy,
  122.  
  123. I'll mail you a few .cshrc and .login files.  Unfortunately, I'm short on
  124. time... so I can't comment a lot... but I'd be glad to answer any questions
  125. you've got about how they work.
  126.  
  127. A summary of them:
  128.  
  129. 1)  This .cshrc file comes from the tektronix!tekred machine in Redmond,
  130. Oregon.  Its neat feature is that, when a user "su"'s to someone else's
  131. account, their prompt changes
  132. from    %
  133. to    account>
  134. where the "su"'d name appears before the >.  Very nice, I think.
  135.  
  136. Also, they do a standard thing around here.  The first line [if ($?prompt)]
  137. checks to see if the .cshrc is being scanned by an interactive shell.  If so,
  138. the commands below are executed.  If not (like a shell escape from "vi"), the
  139. commands aren't executed.  This really speeds up shell escapes!  (I do the
  140. same thing, in a different way, in my .cshrc file.)
  141.  
  142.  
  143. 2)  This is my .login file.  I should mention that I've got my own calendar
  144. system that's updated every morning at 1 AM by "at".  It sits in my
  145. ".calendar" directory.  You'll see a lot of that stuff in the .login file.
  146.  
  147.  
  148. 3 & 4)  I have *two* .cshrc files.  One, ".cshrc", is the standard file.  It
  149. contains a limited list of aliases and setup commands.  The other, ".cshrc2",
  150. is one I source when I'll be logged on for a long time and doing a lot of
  151. work.  The .cshrc2 has time-saving aliases like "alias m more" in it.  
  152.  
  153. At login, the .cshrc is always read.  This sets my prompt to something like
  154.     <directory,#>
  155. where # is the C-shell history number.  Also, since my system is so busy, I
  156. have a "quick login" setup in .cshrc to let me see my mail immediately and
  157. logout without doing anything else, if I want to.  This quick-login has a
  158.     $
  159. prompt set... the Bourne-shell prompt.
  160.  
  161. If I want an extended login, I execute the alias "res" (from .cshrc).  It sets
  162. alarms automatically (for meetings, etc... from my .calendar directory) and
  163. re-sets my prompt to something like
  164.     [directory,#]
  165. That way, I know that I've got all my aliases available.
  166.  
  167. Since my system is overloaded, this dual-.cshrc system saves me time and
  168. hassle... .cshrc2 takes a long time to source.
  169.  
  170.  
  171. --Jerry Peek, UNIX Training Instructor, Tektronix, Inc.
  172. US Mail:   MS 76-036, P.O. Box 500, Beaverton, OR 97077
  173. uucp:      {allegra,decvax,hplabs,ihnp4,mit-eddie,ucbvax}!tektronix!jerryp
  174. CSnet:     jerryp@tek
  175. ARPAnet:   jerryp.tek@csnet-relay
  176. Phone:     503/627-1603
  177.  
  178.  
  179. ---------------------------------------------------------------------------
  180. FILE #1 (.cshrc):
  181.  
  182. if ($?prompt) then
  183.     set history=20
  184.     set path=(. $home/bin /usr/local /usr/tek /usr/public /usr/ucb /bin /usr/bin)
  185.     set mail=(300 /usr/spool/mail/$home:t /etc/motd)
  186.     source ~/.aliases
  187.  
  188.     set prompt=`whoami | sed -e 's/ .*//' -e 's/user=//'`
  189.     if ($prompt == $user || $prompt == "") then
  190.         set prompt="% "
  191.     else
  192.         set prompt="$prompt> "
  193.     endif
  194. endif
  195. ---------------------------------------------------------------------------
  196. FILE #2 (.login):
  197. uptime            # show system load
  198. set ignoreeof        # do not logout on EOF (^D)
  199. set noclobber        # do not overwrite files with > or >>
  200. cp ~/.exrc8 ~/.exrc    # set up vi/ex to environment in ~/.exrc8
  201. setenv EDIT /usr/ucb/vi    # set default editor to vi
  202. setenv PRINTER uph    # if type "man -Tlpr", use "uph" to store for printing
  203. setenv NEWSBOX ~    # save news (readnews "s") in home directory or beneath
  204.  
  205. set noglob; eval `tset -srQm 'plugboard:?4025'`; unset noglob
  206.  
  207. stty new crt        # new tty driver, crt terminal, see newtty(4)
  208. stty tostop hup     # stop background jobs on output, hangup hw on logout
  209. limit filesize 2000    # do not write file > 2,000,000 bytes
  210. limit coredumpsize 0    # prevent core dumps when csh bombs
  211. touch .llog        # set correct last login time for finger
  212. if ($TERM == 'tek4023' || $TERM =~ aaa*inv ) then
  213.     # KEEP more FROM USING THE ul OPTION AND MESSING UP DISPLAY:
  214.     setenv MORE -u
  215. else if (($TERM == qume5) || ($TERM == dumb)) then
  216.     mesg n
  217.     exit 0
  218. endif
  219.  
  220. # immediate notification (every 60 seconds) of mail:
  221. set mail = (60 /usr/spool/mail/$user /etc/motd)
  222.  
  223. # check /etc/motd for changes; if any, show them and (maybe) add to calendar:
  224. diff ~/.calendar/last.motd /etc/motd >! /tmp/motd.diff
  225. if ( $status != 0 ) then
  226.     echo "< = old MOTD ... > = new MOTD"
  227.     more /tmp/motd.diff
  228.     echo "To read the new MOTD into the calendar, answer y.  To ignore it, answer q."
  229.     echo -n "Otherwise, hit RETURN: "
  230.     set ans = $<
  231.     if ($ans == "y") then
  232.         cat /etc/motd | tee -a ~/.calendar/calendar >! ~/.calendar/last.motd
  233.         vi + ~/.calendar/calendar
  234.         echo "To reset *today's* calendars, type 'calendar.set -F'."
  235.     else if ($ans == "q") then
  236.         cat /etc/motd >! ~/.calendar/last.motd
  237.     endif
  238. endif
  239.  
  240. echo "--------------------"
  241. inc        # put new mail, if any, in ~/.mail/inbox
  242.  
  243. echo "--------------------"
  244.  
  245. set time = 10    # for jobs that take longer than 10, show how long
  246. # IF THERE ARE LOGIN MESSAGES, SHOW THEM:
  247. if !(-z ~/.calendar/mesg.login) then
  248.     echo "Here are the login messages, "`date '+%a %D'`
  249.     echo ""
  250.     doublespace ~/.calendar/mesg.login
  251. endif
  252.  
  253. echo "For an uptime graph, type 'upgr'."
  254. ---------------------------------------------------------------------------
  255. FILE #3 (.cshrc):
  256. # if this is a non-interactive shell, quit.
  257. if ( ! $?prompt) exit 0
  258.  
  259. # save login system search path, removing leading "." (thanx to tekig!danr):
  260. if ( ! $?SYSPATH ) setenv SYSPATH "$path[2-]"
  261.  
  262. # set default places to find commands (put current and .bin directories first):
  263. set path=(. ~/.bin $SYSPATH /usr/public{,/texthelp} /usr3/{barbaraz/.,tcomm/}bin)
  264.  
  265. # CHECK FOR QUICK LOGIN:
  266. if (! $?LOGGEDIN) then
  267.     echo -n "For quick login (Bourne shell), answer y; otherwise, press RETURN: "
  268.     if ( "$<" =~ y* ) then
  269.         echo "To continue with login, press control-D; to logout, type 'stty 0'"
  270.         /bin/sh -i
  271.         echo "Continuing with standard login..."
  272.     endif
  273. endif
  274. setenv LOGGEDIN x
  275.  
  276. # set cd search path for directory names which aren't sub-directories:
  277. set cdpath=(~ `finddirs ~/training{,/*} /usr3/tcomm/unix{,/*}` ~/.bin ~/.log ~/.mail ~/stuff ~/tape*)
  278.  
  279. set history=1000    # keep the last 1000 commands in history
  280.  
  281. # use /usr/public/prompt to get massaged directory name for prompt-setting:
  282. set prompt = "<`prompt ~ $cwd`,"{\!}"> "
  283.  
  284. # edit my calendar:
  285. alias calen 'vi ~/.calendar/calendar; echo '"To reset today\'s calendars, type calendar.set -F"''
  286.  
  287. # change directory, reset prompt:
  288. alias cd 'chdir \!*; set prompt = "<`prompt ~ $cwd`,"{\!}"> "'
  289.  
  290. # add to specified .log directory
  291. alias log 'echo "Put a .ze at end of file, unless last log of this set.";vi + ~/.log/`cat ~/.log/latestlog`/\!*'
  292.  
  293. # create newterm command to allow terminal-type change
  294. alias newterm 'set noglob;eval `tset -srQ \!*`;unset noglob'
  295.  
  296. # sets alarms (if any) and sources '.cshrc2' (my other alias list)
  297. alias res '~/.bin/alarm.set ; source ~/.cshrc2'
  298.  
  299. alias todo 'vi ~/todo\!*'    # change one of the "to do" lists
  300. ---------------------------------------------------------------------------
  301. FILE #4 (.cshrc2):
  302.  
  303. # notify immediately when background jobs are finished
  304. set notify
  305.  
  306. # prompt with current directory name, history number:
  307. alias s_p 'set prompt = "[`prompt ~ $cwd`,"{\!}"] "'
  308. s_p
  309.  
  310. # set 'vi' for 4-character tabs/shifts:
  311. alias 4vi 'cp ~/.exrc{4,}; echo "MODE: programming"'
  312.  
  313. # set 'vi' for 8-character tabs/shifts:
  314. alias 8vi 'cp ~/.exrc{8,}; echo "MODE: text"'
  315.  
  316. # set 'vi' for quick work (no .exrc file):
  317. alias qvi 'rm ~/.exrc; echo "MODE: quick"'
  318.  
  319. # easy way to compile "C" programs (ring bell if filename ends with ".c"):
  320. alias C 'if ("\!*" =~ *.c) yes ;mv \!* ,\!*;echo \!*.c" SENT TO cc";cc \!*.c -o \!*;if (-e \!*) chmod 311 \!*'
  321.  
  322. # show alarms that (may be) set... and message explaining them:
  323. alias alarms 'echo "These alarms have been set:";cat ~/.calendar/mesg.alarm; \ps | fgrep ".bin/nleave"'
  324.  
  325. # change back to previous directory:
  326. alias c- 'set x=$cwd; chdir $lastdir; s_p; set lastdir=$x'
  327.  
  328. # edit my calendar:
  329. alias calen 'v8 ~/.calendar/calendar; echo '"To reset today\'s calendars, type calendar.set -F"''
  330.  
  331. # see today's calendars:
  332. alias cals 'cat ~/.calendar/mesg.*'
  333.  
  334. # save current directory for 'c-', change directory, reset prompt:
  335. alias cd 'set lastdir=$cwd; chdir \!*; s_p'
  336.  
  337. # see mail without inc'ing it:
  338. alias checkm 'see /usr/spool/mail/jerryp'    
  339.  
  340. # same as 'cd', but lists directory, too:
  341. alias cl 'set lastdir=$cwd; chdir \!*; ls -F; s_p'
  342.  
  343. # same as 'cl', but gives long list:
  344. alias cll 'set lastdir=$cwd; chdir \!*; ls -l; s_p'
  345.  
  346. alias f 'grep "^\!*" /etc/passwd'    # quick version of "finger -s"
  347.  
  348. alias H 'history -r | fgrep "\!*"'    # find something in history list
  349. alias h history 5    # show last five lines
  350. alias hi history 10    # show last ten lines
  351. alias his history 20    # show last twenty lines
  352. alias hist 'history 40|m'    # show last forty lines; pipe to 'more'
  353. alias histo 'history 70|m'    # show last seventy lines; pipe to 'more'
  354.  
  355. # send output of command to 'pr' (with command as header), then to uph:
  356. alias hpr '\!* | pr -h "\!*" | uph' 
  357.  
  358. alias j 'jobs -l >! /tmp/j$$; pushin /tmp/j$$; rm /tmp/j$$'
  359. # show job status (process numbers, too) squeezed onto one line each
  360.  
  361. alias lc 'ls *.c'    # list all C source code in this directory
  362.  
  363. # add to specified .log directory
  364. alias log 'echo "Put a .ze at end of file, unless last log of this set.";v8 + ~/.log/`cat ~/.log/latestlog`/\!*'
  365.  
  366. # list executable files, 5 columns, sorted across 80-wide line:
  367. alias lx 'lf -1 | fgrep \* | pr -t -5 -l1 -w80'
  368.  
  369. alias m more        # shortened form of 'more' command
  370.  
  371. # faster pwd (singlequotes prevent expansion before it's executed):
  372. alias pwd 'echo $cwd'
  373.  
  374. # re-start inverse video on Ann Arbors:
  375. alias reinv 'echo "[7m";clear'    
  376.  
  377. # lock terminal until ^C and login password are entered:
  378. alias somb /usr3/jos/bin/somb
  379.  
  380. alias showm 'inc;show'    # get new mail
  381.  
  382. # give more info (how much time I've used) when using "status":
  383. alias status 'source ~/.bin/status'
  384.  
  385. alias tcpr 'tcprint -p12 -m5 -ff \!* &'        # typical quick "tcprint" use
  386.  
  387. alias todo 'v8 ~/todo\!*'    # change one of the "to do" lists
  388.  
  389. alias up uptime
  390.  
  391. # make uptime graph:
  392. alias upgr '(nohup uptime_graph ~/,up`date +%m%d.%H%M` &)'
  393.  
  394. # show uptime today's graph:
  395. alias upsh 'uptime_show -20 ~/,up`date +%m%d`*'
  396.  
  397. # 'vi' for programming:
  398. alias v4 '4vi;vi \!*'
  399.  
  400. # 'vi' for standard text:
  401. alias v8 '8vi;vi \!*'
  402.  
  403. # call 'vi' with a search (must use 8vi because search requires a 'wrapscan')
  404. alias vs '8vi; vi +/\!*'
  405.  
  406. alias write '/usr4/danr/bin/rite -c \!*'   # show each character as it's typed
  407.  
  408. #UNUSED ALIASES:
  409. #alias cd 'set lastdir=$cwd;chdir \!*;set prompt="`~/.bin/prompt`"'
  410. # change to maps directory:
  411. #alias maps 'cd /usr/spool/news/lib/maps;echo "switching to newsa";su newsa;set $user=jerryp;c-'
  412. # keep "at" job from dying because of long EXINIT:
  413. #alias niterun 'setenv EXINIT "set sw=8";\niterun \!*;8vi'
  414. #alias du ~danr/bin/du    # improved version of "directory usage" query
  415. # format text, save in file".ty", then show it on the crt:
  416. #alias typeup '~/.bin/type \!* >! \!*:r; more \!*:r'
  417. # give description of 'ps' codes before doing the 'ps':
  418. #alias ps 'cat ~/.ps.man;\ps \!*'
  419. # easy way to compile and run "C" programs
  420. # (ring bell if filename ends with ".c"):
  421. #alias c 'if ("\!*" =~ *.c) yes ;mv \!* ,\!*;echo \!*.c" SENT TO cc";cc \!*.c -o \!*;echo "press ^C to stop execution";sleep 2;./\!*'
  422. # easy way to change editor environment files:
  423. #alias adde 'vi ~/.exrc\!*; set ex=(`cat ~/.exrc\!*`); setenv EXINIT "$ex"'
  424. #alias rmm '\rmm \!* &'  # remove mail in background
  425. # faster "man" listings:
  426. #alias man 'echo "man -q:"; \man -q \!*'
  427. # improved spell routine (write-protected dictionary):
  428. #alias spel 'chmod +w ~/.misspell; /usr/public/spel \!*;chmod -w ~/.misspell'
  429. # show whether using ~/.exrc4 or ~/.exrc8:
  430. #alias vi 'echo "MODE: "$EXSTAT;/usr/ucb/vi \!*'
  431. #alias comp '8vi;\comp \!*'    # set 'vi' for text before doing the 'comp'
  432. # show last ten users of "tcprint" program:
  433. #alias tcp tail /usr3/tcomm/.tcprint/log
  434. # favorite "ps" (gives PID, PPID, STAT, TT, TIME, and long description):
  435. #alias p 'ps lwx | cut -c12-22,53- | nfold'
  436.  
  437. ::::::::::::::
  438. cshrc/2
  439. ::::::::::::::
  440. Date: Thu, 13 Sep 84 02:16:31 edt
  441. From: ihnp4!seismo!umcp-cs!chris (Chris Torek)
  442. To: ihnp4!resonex!nancy
  443. Subject: Re:  Tricks, shell and awk scripts, ...
  444.  
  445. Actually Re: [Know anybody with a GREAT .login or .cshrc?]:
  446.  
  447. I don't know about *great*, but I'm probably one of the candidates for
  448. *slowest* . . . .  FYA (For Your Amusement), here's my .login and .cshrc
  449. on this machine (they're not the same on tove, gyre, gymble, and eneevax).
  450.  
  451. Chris
  452.  
  453. : Run this shell script with "sh" not "csh"
  454. PATH=:/bin:/usr/bin:/usr/ucb
  455. export PATH
  456. all=FALSE
  457. if [ $1x = -ax ]; then
  458.     all=TRUE
  459. fi
  460. /bin/echo 'Extracting .cshrc'
  461. sed 's/^X//' <<'//go.sysin dd *' >.cshrc
  462. #
  463. if ($?prompt) then
  464. echo -n '['
  465. set path=(. ~chris/bin ~chris/sys /usr/local/bin /g/local /usr/ucb /bin /usr/bin /usr/games /etc /usr/hosts)
  466. echo -n 'cshrc]'
  467. set ignoreeof history=100 time=2 mail=(10 /usr/spool/mail/chris) cdpath=(~ /g/VOTRAX ~/bin /g/chris ..) S=/usr/spool/uucp CICO=/usr/lib/uucp/uucico
  468. alias hh history;alias h 'history 20';alias j jobs;alias o popd
  469. alias status 'echo $status';alias so source;alias bye logout
  470. alias p pushd;alias done 'echo ';alias kb "rm -i .*.bak *.bak .*.CKP *.CKP"
  471. alias kc "rm -i .*.CKP *.CKP";alias e emacs;alias @@term 'kill -9 $$'
  472. alias af ~chris/af/af;alias cdl "cd \!:1;ls \!:2*";alias lsl "ls -li"
  473. alias lsa "ls -A";alias lsla "ls -lai";alias up "cd ..";alias upl "cd ..;ls"
  474. alias cdll "cd \!:1;lsl \!:2*";alias lsld "lsl -d";alias lslg "lsl -g"
  475. alias upll "cd ..;lsl";alias pl "pushd \!:1;ls \!:2*";alias z logout
  476. alias pll "pushd \!:1;lsl \!:2*";alias ol "popd;ls";alias oll "popd;lsl"
  477. alias cdla "cd \!:1;lsla \!:2*";alias v80 'echo -n "[?2l";set term=VT52'
  478. alias v132 'echo -n "[?2l";set term=VT52.132';alias ansi 'echo -n "<"'
  479. alias fix 'stty newcrt erase  kill ';alias ca 'ex "+1,.|q"' 
  480. alias own 'cp \!:1 /tmp/own$$;rm -f \!:1;mv /tmp/own$$ \!:1'
  481. alias save 'cp \!:1 \!:1.old;chmod a-w \!:1.old;chmod +w \!:1'
  482. alias c80 'echo -n "[?3l";set term=DT80';alias suspend 'suspend;dirs'
  483. alias col80 'echo -n "[?3l";colnum 80';alias a alias
  484. alias c132 'echo -n "[?3h";set term=DT80.132'
  485. alias col132 'echo -n "[?3h";colnum 132'
  486. alias hold 'echo -n "[H[J[12;20H[5mI'"'"'ll be right back[m[20H";lock;echo -n "[H[J"'
  487. alias feed '(sleep 3000;echo Feeding time\\!)&'
  488. alias open 'set noglob;eval `/usr/chris/bin/open \!:*`;unset noglob'
  489. alias loav /usr/mark/bin/load
  490. setenv VISUAL /usr/ucb/vi;setenv EDITOR /usr/local/bin/emacs
  491. setenv EPATH :/usr/chris/emacs:/usr/israel/emacs:/usr/emacs/loclib:/usr/emacs/maclib
  492. alias dir ls;alias era rm;alias printman /usr/man/printman;alias d dirs
  493. alias clx 'rm -f /tmp/X_lock.\!:1 /usr/spool/uucp/LCK..\!:1'
  494. alias aasize 'set noglob;eval `/usr/local/bin/aasize \!:1`;unset noglob'
  495. alias aasave 'set noglob;eval `/usr/local/bin/aasave \!:1`;unset noglob'
  496. alias down 'cd `echo */|awk '\''{print $1}'\''`;echo $cwd'
  497. alias downl 'down;ls';alias downll 'down;lsl';alias mark 'set \!:1=$cwd'
  498. alias lso 'lsla | sort +4 -rn';alias edenv 'source ~chris/bin/edenv'
  499. alias aibib 'echo \!*|lookbib -n -p /usr/randy/papers/airefs|page'
  500. alias checkque /usr/lib/mmdf/checkque;alias sum-dial /usr/lib/mmdf/sum-dial
  501. alias deliver 'sh -c "HOME=/ /usr/lib/mmdf/deliver \!:*"'
  502. alias ll 'ls -l';alias tm 'telnet 128.8.0.8'; alias  uptime
  503. endif
  504. umask 22
  505. if ($?prompt) then
  506.     set prompt='[\!] '
  507.     echo ''
  508. endif
  509. //go.sysin dd *
  510. made=TRUE
  511. if [ $made = TRUE ]; then
  512.     /bin/chmod 644 .cshrc
  513.     /bin/echo -n '    '; /bin/ls -ld .cshrc
  514. fi
  515. /bin/echo 'Extracting .login'
  516. sed 's/^X//' <<'//go.sysin dd *' >.login
  517. #
  518. stty erase ^H kill ^X intr  decctlq nl0 cr0 ff0
  519. cd;setenv TERMCAP /usr/chris/.termcap
  520. # cp .exrc1 .exrc
  521. # Set up the terminal
  522. # 4025=Tek4025 sd=dialup x1=Xer 1750 GG=Gigi d4=GT40 aaa=AAA else DT80
  523. # if (`slowtty` == y) then
  524. #    cp .mailrc2 .mailrc
  525. # else
  526. #    cp .mailrc1 .mailrc
  527. # endif
  528. set wantbaud=0
  529. top:
  530. switch ($TERM)
  531. case su:
  532. case network:
  533.     set wantbaud=1
  534. case sd:
  535. case unknown:
  536.     set term=`/ful/chris/bin/selterm`
  537.     goto top
  538. case 4025:
  539.     stty crt tabs;tabset.tek
  540.     breaksw
  541. case h6:
  542. case hp:
  543. case hp2623:
  544. case hp2626:
  545.     stty tabs crt
  546.     breaksw
  547. case v550:
  548.     stty crt;set prompt='[7m[\!][m '
  549.     breaksw
  550. case GG:
  551.     stty crt;unsetenv TERMCAP;set prompt='[7m[\!][m '
  552.     breaksw
  553. case d4:
  554.     set term=gt40;stty crt
  555.     breaksw
  556. case aaa:
  557. case aaa-60:
  558.     set term=aaa prompt='[7m[\!][m ';stty tabs crt;unsetenv TERMCAP
  559.     aakey -f /ful/chris/.aakeys
  560.     if (`tty` =~ /dev/tty*) then
  561.         echo -n 'Lines? [30] '
  562.         set lines=$<
  563.         if ($lines != ) then
  564.             aasize $lines
  565.         endif
  566.     endif
  567.     breaksw
  568. case h19:
  569. case h19a:
  570. case kb:
  571.     set term=h19a prompt='[7m[\!][m ';stty tabs crt crtkill
  572.     breaksw
  573. case Dq:
  574. case DT80:
  575. case D5:
  576. case vt100:
  577.     set term=DT80 prompt='[7m[\!][m '
  578.     echo -n '[?4l';stty crt
  579.     breaksw
  580. default:
  581.     unsetenv TERMCAP;echo "Wonder what $TERM is?"
  582.     breaksw
  583. endsw
  584. if ($wantbaud == 1) then
  585.     selbaud
  586. endif
  587. unset wantbaud lines
  588. # mailcount
  589. checknews
  590. setenv ROGUEOPTS 'jump,ask,terse,flush,passgo,fruit=hregfx'
  591. setenv PAGER /usr/ucb/page
  592. setenv SPELL_LISTS /ful/chris/.splist
  593. alias logout 'source /ful/chris/.logout.';alias exit logout
  594. # /usr/games/fortune
  595. w; # calend; /usr/chris/bin/ac 22:00
  596. echo ----------------------------------------------------------
  597. # rehist .history
  598. //go.sysin dd *
  599. made=TRUE
  600. if [ $made = TRUE ]; then
  601.     /bin/chmod 644 .login
  602.     /bin/echo -n '    '; /bin/ls -ld .login
  603. fi
  604.  
  605. ::::::::::::::
  606. cshrc/3
  607. ::::::::::::::
  608. Date: Fri, 14 Sep 84 14:59:01 pdt
  609. From: hplabs!sdcrdcf!sdcsvax!sdcc6!loral!hlb (Howard Brandell)
  610. To: sdcc6!sdcsvax!sdcrdcf!hplabs!resonex!nancy
  611. Subject: .cshrc
  612.  
  613. I am sending my entire .cshrc file because I have some things in it
  614. that help me out.
  615.  
  616. Firstly, note the aliases that allow me to selectively read those
  617. newsgroups of interest.  Aha! You may say I can put it all in the
  618. .newsrc file and have the system inform me when there is news and
  619. read it out simultaneously.  But, sometimes we get news during the
  620. course of the day and I like to check my favorites continuously.
  621.  
  622. Also, not the aliases for tip.  These allow me to dial my remote 
  623. locations with both spped and accuracy. As an aside,  I have
  624. created a .tiprc file which logs all my remote host conversation
  625. into a file.  In this way, nothing is lost.  Note the 'rt' command
  626. which allows me to purge tiplog.
  627.  
  628. alias a alias
  629. a sd   "msg,gju,glw,kay,sdi"
  630. a ds   "chmod 600 .signature"
  631. a es   "chmod 640 .signature"
  632. a vc   "ccalc"
  633. a m    "mail"
  634. a p    "more"
  635. a rk   "readnews -n net.kids"
  636. a ra   "readnews -n net.micro.apple"
  637. a ri   "readnews -n net.micro.pc"
  638. a rs   "readnews -n sdnet.computing"
  639. a rb   "readnews -n net.sport.baseball"
  640. a rn   "readnews -n net.columbia"
  641. a rw   "readnews -n net.wanted"
  642. a rl   "readnews -n net.legal"
  643. a r    "readnews"
  644. a logs "readnews -n net.sources -l>sources.log"
  645. a motd "cat /etc/motd|more"
  646. a h   "history -r \!*|more"
  647. a t1  "tip 561-7271"
  648. a t2   "tip 452-1869"
  649. a t3   "tip 283-1538" 
  650. a t4   "tip 692-1961"
  651. a t5   "tip 270-1166" 
  652. a t6   "tip 217-1900"
  653. a rt   "rm tiplog"
  654. a bye     logout
  655. a cd    "cd \!* ; dirs"
  656. a term    'set noglob; eval `tset -n -s \!*`'
  657. a wat    "ps -au | more"
  658. a pv    printenv
  659. a j    "jobs -l"
  660. a f    "finger|more"
  661. a l    ls -F
  662.  
  663. if ( $?prompt == 1 ) then
  664.     set prompt="\!: "
  665.     set mail=(60 /usr/spool/mail/$USER)
  666. endif
  667. set history =    24
  668. set cdpath = (. ~)
  669.  
  670. Also note the aliases for the more mundane commands, like mail
  671. and more -c.
  672.  
  673. Hope this has been of some help.  Please disregard my earlier
  674. transmission as I had some operational difficulties.  Thx.
  675.  
  676. ::::::::::::::
  677. cshrc/4
  678. ::::::::::::::
  679. From: sun!dagobah!mike
  680. Date: Mon, 17 Sep 84 23:27:05 pdt
  681. To: sun!resonex!nancy
  682. Subject: .cshrc
  683.  
  684. set mail=(10 /usr/spool/mail/$user)
  685. set path=(. ~/bin /usr/lfl/bin /usr/ucb /bin /usr/bin /usr/hosts /usr/suntool)
  686. set cdpath  = ( . .. ~ /usr /u0 /u1 /audio)
  687. set mail=(10 /usr/spool/mail/$user)
  688. set msgs=(10 /usr/msgs/bounds)
  689. set history = 50
  690.  
  691. source  ~/.aliases
  692. set D = /net/dagobah/u0/mike
  693. set d = /net/dim/u0/mike
  694. set k = /net/kessel/u0/mike
  695. set n = /net/nellybell/u0/mike
  696. if (! $?HOST) setenv HOST `hostname`
  697. alias s_prompt 'set prompt = "[$HOST\\\!$cwd]\\
  698. % "'
  699. alias cd 'cd \!*; s_prompt'
  700. s_prompt
  701.  
  702.  
  703. ::::::::::::::
  704. cshrc/5
  705. ::::::::::::::
  706. From: sun!dagobah!mike
  707. Date: Mon, 17 Sep 84 23:27:19 pdt
  708. To: sun!resonex!nancy
  709. Subject: .aliases
  710.  
  711. alias alice    cu -s 1200 2016654115
  712. alias rabbit    cu -s 1200 2016654150
  713. alias yale    cu -s 1200 2034323510
  714. alias ajax    cu -s 1200 2015828265
  715.  
  716. alias ts     'setenv TERM `tset - \!* -Q`;set term = $TERM;unsetenv TERMCAP;'
  717. alias aa    "ts aaa-26; aaapf"
  718. alias aaa    aa
  719.  
  720. alias h        history
  721. alias l        'ls -Fa'
  722. alias lp    l -t
  723. alias ll    'ls -laF | more'
  724. alias wo    /u0/td/bin/who
  725. alias m        'make \!* >>& errors &'
  726. alias mail    Mail
  727. alias ml    /bin/mail
  728. alias lm    ml
  729. alias rml    'rm -f /usr/spool/mail/mike'
  730. alias RM    '/bin/rm -rf'
  731. alias clean    'rm *.o core errors a.out'
  732. alias CLEAN    'RM *.o core errors a.out ~/.REMOVED; mkdir ~/.REMOVED'
  733. alias die    'clear; kill -HUP $$'
  734. alias tlog    tail -f /usr/spool/uucp/LOGFILE
  735. alias ter    tail -f errors
  736.  
  737.   #
  738.   # For job control:
  739.   # Use 'fg' to bring job into the foreground, 'bg' to run job in background.
  740.   #   'v', to restart vi editor
  741.   #   'W', to restart ice editor
  742.   #   'j', to list out jobs
  743.   #   'k', to kill jobs; 'k 2' kills job [2]; 'k' kills the most recent job (+).
  744. alias v       %vi
  745. alias j       jobs
  746. alias k       'kill %\!*'
  747. alias sysline ~/bin/sysline -Dhmrj
  748.  
  749.  
  750. ::::::::::::::
  751. cshrc/6
  752. ::::::::::::::
  753. Date: Fri, 21 Sep 84 01:17:43 cdt
  754. From: ihnp4!uiucdcs!liberte (Daniel LaLiberte)
  755. To: sun!resonex!nancy
  756. Subject: .cshrc trick
  757.     
  758. I like my recursive prompt that shows the depth of shell calls with added
  759. ">"s.  It also gives a different prompt for my superuser which has the same
  760. home.  Additionally, we have several vaxes, uiucdcs*, networked with
  761. ethernet.  Upgrades are easier with the same .cshrc on all machines.
  762.     
  763.     
  764. ...
  765. if (! $?PROMPT) setenv PROMPT ""    # initialize
  766. setenv PROMPT "$PROMPT>"        # add ">"
  767. if ($?prompt) then
  768.     set sys = `hostname`
  769.     if ("$prompt" == "% ") then    # regular user
  770.         set prompt = `echo $sys | sed s/uiucdcs//`
  771.     else if ("$prompt" == "# ") then    # super user
  772.         set prompt = "$sys#"
  773.     endif
  774.     set prompt = "$prompt\!$PROMPT "
  775. endif
  776.     
  777.     
  778. My login prompt (on uiucdcs) is:
  779.     
  780. 1>
  781.  
  782. A csh call will produce:
  783.     
  784. 1>>
  785.     
  786. Remote login to uiucdcsb, for example:
  787.     
  788. b1>
  789.     
  790. Superuser on uiucdcsb:
  791.     
  792. uiucdcsb#1>>
  793.     
  794.     
  795. I have an alarm script and a spooled rcp that both use `at`.
  796.  
  797. Daniel LaLiberte
  798. ihnp4!uiucdcs!liberte
  799.  
  800.  
  801. ::::::::::::::
  802. cshrc/7
  803. ::::::::::::::
  804. Date: Sun, 7 Oct 84 20:35:02 pdt
  805. From: Ken Greer <hplabs!kg>
  806. To: resonex!nancy
  807. Subject: Xmas is early this year...
  808.  
  809. Here's what I thought were the most interesting things in my 
  810. csh profile.
  811.  
  812. 1. Prompt is (curdir hist#), or [curdir hist#] if running as su.
  813.    The brackets stack, so if I login as kg and su to kgsu, my prompt
  814.    is [(curdir hist#)] indicating my previous shell was non-su.
  815.    In both cases, the current directory always appears in prompt.
  816.  
  817. 2. On that subject, I heartily recommend a separate su login
  818.    for each su-er on a system.  This lets everyone have their
  819.    own profile, and when they quit you don't have to change the su passwd,
  820.    just remove their su.
  821.  
  822. 3. The directory stuff. (I prefer it to pushd/popd.)
  823.    ds   - displays directory stack (set to length DSSIZE below).
  824.    go # - go to directory item number #
  825.    back - go to previous directory.
  826.    cd   - stack current directory and go to a new one.  Oldest directories
  827.       fall off end of stack (whose size is DSSIZE).
  828.  
  829. 4. The "e" and "ec" commands let you edit the last or any command.
  830.    If works with a special program.  Would you like that?
  831.  
  832. 5. Delete/Undelete - special program.  Lets you recover deleted
  833.    files up to three days (user selectable).
  834.  
  835. 6. Do you know about my tcsh?  Not sure how it fits in with tricks though.
  836.  
  837.                 -Ken
  838.  
  839.  
  840. # Fancy prompt...
  841. if ($?prompt) then
  842. if (! $?LEFTPROMPT) setenv LEFTPROMPT ""
  843. if (! $?RIGHTPROMPT) setenv RIGHTPROMPT ""
  844. if (`whoami` == root) then
  845.     setenv LEFTPROMPT '['"$LEFTPROMPT"
  846.     setenv RIGHTPROMPT "$RIGHTPROMPT"']'
  847.    set path=(~/bin /usr/local/etc /etc /usr/local/bin /usr/ucb /bin /usr/bin .)
  848. else
  849.     setenv LEFTPROMPT '('"$LEFTPROMPT"
  850.     setenv RIGHTPROMPT "$RIGHTPROMPT"')'
  851.     set path=(~/bin /usr/local/bin /usr/ucb /bin /usr/bin .)
  852. endif
  853. alias setprompt 'set prompt = "${LEFTPROMPT}${cwd} \\!${RIGHTPROMPT} "'
  854. setprompt
  855. alias a    alias
  856.  
  857. # directory manipulation...
  858. set DSSIZE = 10
  859. if (! $?DS) set DS = (~)
  860. a back    'set xx=$DS[$#DS] DS[$#DS]=$cwd; chdir $xx; unset xx; setprompt'
  861. a go    'set xx=$DS[\!*] DS[\!*]=$cwd; chdir $xx; unset xx; setprompt'
  862. a ds    'echo $DS | tr " " "\012" | cat -n'
  863. a cd   'if ($#DS >= $DSSIZE) shift DS; set DS = ($DS $cwd);chdir \!*; setprompt'
  864.  
  865. # virtual remove...
  866. a rm    del
  867. a rm!    /bin/rm
  868.  
  869. # edit command...
  870. a e    '/usr/local/bin/ec \!-1:q'
  871. a ec    '/usr/local/bin/ec "\!*:q"'
  872.  
  873. # misc...
  874. a j    jobs
  875. a ls    '/usr/ucb/ls -F'
  876. a tag    '/usr/ucb/vi -ta \!*'
  877. a ts    'set noglob;eval `tset -s -Q \!*`'
  878. a wd    'echo $cwd'
  879. endif
  880.  
  881.  
  882. ::::::::::::::
  883. cshrc/8
  884. ::::::::::::::
  885. Date: Thu, 13 Sep 84 08:36:47 edt
  886. From: sun!decvax!genrad!teddy!dls (Diana L. Syriac)
  887. To: genrad!decvax!decwrl!sun!idi!resonex!nancy
  888. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  889.  
  890. I'm sorry, I don't really have any "tricks" to make life easier, I'm also
  891. a rather new Unix user....except for one:
  892.     I use setenv a lot to define a bunch of directories that I use
  893.     a lot.  For example, I have in my .cshrc:
  894.         setenv obc ~doc/rts/obc
  895.     So anytime I want to get to that directory (or just look at it), I
  896.     just type:    ls $obc/filename
  897.     These environment variables work inside of mail as well as inside of
  898.     emacs.
  899. I suppose you already have that one from other people.
  900.  
  901. We also have on our system some "local" programs that make life a lot easier:
  902. We have an "lf" and "dir" that replaces "ls" and "ls -l", but with an added
  903. feature:  directories are displayed in bold letter, executables are displayed
  904. in reverse video and special files are displayed in flashing letters.  It's
  905. quite easy to see at a glance what the files are or where you want to go.
  906.  
  907. We also have a "pushd" and "popd" which replace the "cd" command.  
  908.     pushd directory
  909. will pushd a directory onto the "stack", and change to it.  After you're
  910. finished with that directory, just typing
  911.     popd
  912. will put you back to where you were.  There is a "dirs" command to 
  913. allow you to look at the "stack" to see where you are, where you've been.
  914. If you use "cd" instead, it's smart enough to change your stack and replace
  915. the current directory with the one specified in "cd". And if you just say
  916. "pushd" by itself, it will SWAP the current directory with the last directory
  917. you were in, making it very easy to toggle between two directories.
  918.  
  919. Other things that we've done:
  920.     Built a script for the nroff command that is used by most people
  921. on the system, including macros and some "local" filters to make it look
  922. nice on terminal, line printer, and diablo.  I have also created a little
  923. program which can be used in conjunction with nroff to produce "change bars"
  924. at the left margin of documents.  We used the change bars quite a lot under
  925. vms rno.
  926.     We have a set of programs that produce "C" listings, with a table
  927. of contents showing all files AND routines, page numbered and file numbered,
  928. each file has a line number at left margin indicating file and line number
  929. (eg: 3.41 refers to file 3, line 41), and at the very end of listing, there
  930. is a cross-reference of all tokens, giving file.line references.  Part of
  931. this set of programs was taken directly off the net and modified for our
  932. own use.
  933.  
  934. Well, that's all that I can think of for now.  BUT what I really mailed
  935. to you was for something that I want.  At the last DECUS, one of the speakers
  936. demonstrated a little program that he wrote that allowed him to keep a
  937. running log of what he did every day.  The program started up when he logged
  938. on, and ran in the background.  Every 15 minutes, it would beep at him,
  939. asking him to input a line telling what he was currently doing.  If ignored,
  940. it would beep at him every minute until he input something to it.  I don't
  941. know who the guy was, and I lost his business card, but I'd sure like to
  942. get that program if you have it.  Thanks much.
  943.  
  944.             Diana L. Syriac
  945.             GenRad, Concord, Ma.
  946.             decvax!genrad!teddy!dls
  947.  
  948.  
  949. ::::::::::::::
  950. logins/1
  951. ::::::::::::::
  952. From: sun!dagobah!mike
  953. Date: Mon, 17 Sep 84 23:26:53 pdt
  954. To: sun!resonex!nancy
  955. Subject: .login
  956.  
  957. #tset -m dialup:aaa-60 -Q
  958. tset -m dialup:c100-4p -Q
  959. setenv TERM $term
  960. switch ($TERM)
  961.     case dialup:
  962.         set term = aaa-60; setenv TERM $term
  963.         ~/bin/aaapf
  964.         breaksw
  965.     case c100-4:
  966.     case c108-4p:
  967.         sysline
  968.     case c100-4p:
  969.         setkeys
  970. endsw
  971. stty new erase "^?"
  972.  
  973. biff y
  974. setenv notify true
  975. setenv CWD $cwd
  976. setenv SHELL /bin/csh
  977. setenv MAIL ~/Mail
  978. setenv MANPATH /u0/pn/man:/u0/mike/Man:/usr/lfl/man:/usr/man
  979. setenv INCPATH /usr/lfl/include:/usr/include:/u0/mike/Include
  980. setenv LIBPATH /usr/lfl/lib:/lib:/usr/lib:/u0/mike/Lib
  981. setenv LOADPATH /usr/src/lfl/bin/emacs.unipress/emacs4.2/maclib
  982. setenv EDITOR /usr/ucb/vi
  983. uupoll ucbvax
  984. msgs
  985.  
  986.  
  987. ::::::::::::::
  988. logins/2
  989. ::::::::::::::
  990. Date: Fri, 14 Sep 84 10:42:43 edt
  991. From: Jay Weber  <amd!mordor!ut-sally!seismo!rochester!jay>
  992. To: ut-sally!mordor!dual!amd!resonex!nancy
  993. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  994.  
  995. I use the hold option in my .mailrc, which keeps messages around
  996. until you explicitly delete them.  That's a popular option since
  997. it makes it easy to keep around descriptions of things to do, but
  998. it gets hard to tell when you have new mail and how much.  So, I
  999. have this in my .login:
  1000.  
  1001. @ newmail= `from $mail[$#mail] |awk 'END{print NR}'` - `cat .mailsize`
  1002. if ($newmail == 1) then
  1003.   echo "(There is one new mail message.)"
  1004. else
  1005.   if ($newmail > 1) echo "(There are $newmail new mail messages.)"
  1006. endif
  1007. ------------
  1008. and this in my .logout:
  1009.  
  1010. if (-r $mail[$#mail]) then
  1011.   from $mail[$#mail] | awk 'END{print NR}' >~/.mailsize
  1012. endif
  1013. ------------
  1014.  
  1015. Jay Weber
  1016. ..!seismo!rochester!jay
  1017. jay@rochester.arpa
  1018.  
  1019.  
  1020. ::::::::::::::
  1021. logins/3
  1022. ::::::::::::::
  1023. Date: Fri, 14 Sep 84 15:16:00 cdt
  1024. To: ctvax!convex!allegra!resonex!nancy
  1025. From: allegra!convex!trsvax!gm  (George Moore)
  1026. Subject: neat .login's
  1027.  
  1028. Nancy,
  1029.    Here is some of the aliases I use, as well as part of my .login
  1030. file: (We are running 4.1BSD on a 11/780)
  1031.  
  1032.   alias back 'set back=$old; set old=$cwd; cd $back; unset back'
  1033.   alias cd 'set old=$cwd; chdir \!*; sp'
  1034.   alias sp 'set prompt="$cwd> "'
  1035. Those aliases allow my prompt to always be my current directory.
  1036. You never have to run "pwd" again. Looks kindof strange when you
  1037. are in a low directory like /g/usr/src/local/csh, but you get used
  1038. to it. It also allows you to cd to some low dir, and then type
  1039. "back" and you are back in the directory you started in.  
  1040.  
  1041. I have this line in my .login:
  1042.   sh -c "$HOME/bin/firstlog &"
  1043. This line allows you to spin off a background job without the
  1044. "[1] 22934"  message messing up your screen. Firstlog is done
  1045. below. I have a security program which goes out and checks a few
  1046. key files and directories (/etc/passwd, /etc/group, /usr/lib/crontab,
  1047. /etc). If anything has changed, it sends me mail informing me of the
  1048. fact. But I only wish it run once a day, at the time I first login for
  1049. the day. (I don't want it run from crontab, that makes things too
  1050. predictable for the users)
  1051.  
  1052. ---------------------------------------------------------------------
  1053. #! /bin/csh
  1054. #  Firstlog -- finds out if this is the first time I have logged in 
  1055. #              today and start-up all sorts of neat stuff if it is.
  1056.  
  1057. set date=`/bin/date`
  1058. set now=`/usr/ucb/last $user`
  1059. if ($date[2] != $now[13] || $date[3] != $now[14]) then
  1060.     sh -c "$HOME/personal/security/secure &"
  1061. endif
  1062. ---------------------------------------------------------------------
  1063.  
  1064. I hope this helps.                George Moore
  1065.                         gm@trsvax.UUCP
  1066.  
  1067.  
  1068. From: Nancy Blachman <decvax!decwrl!sun!idi!resonex!nancy@Ucb-Vax.ARPA>
  1069. To: net.unix,net.unix-wizards,net.sources
  1070. Subject: Actual Tricks, shells, csh aliases and the like, 2 of 3
  1071. Date: 16 Oct 84 21:22:55 GMT
  1072. Organization: Resonex Inc., Sunnyvale, CA
  1073.  
  1074. > [Know anybody with a GREAT .login or .cshrc?]
  1075.  
  1076. > I'm interested in collecting the little tricks, shell scripts, awk
  1077. > hacks, csh aliases, and such that people have built to make their daily
  1078. > life a little easier or more automatic.  Being a fairly new system
  1079. > administrator I don't have the big toolbox that years of messing around
  1080. > will leave you with.  If you have any hacks you're proud of (or that
  1081. > you aren't proud of, but which work anyway), and you're willing to make
  1082. > them public, mail them to me.  I'll collect, collate, shuffle, sort,
  1083. > munge, judge, select and discard them and then "summarize to the net".
  1084.  
  1085. This article focuses shell scripts I received in response to my solicitation.  
  1086. The first article of this series concentrates on  aliases, and .cshrc and 
  1087. .login files. The third article centers on C programs and awk scripts.
  1088.  
  1089. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  1090. > Nancy Blachman {allegra,hplabs,ihnp4,sun}!resonex!nancy  (408)720 8600 x37 <
  1091. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  1092.  
  1093. ::::::::::::::
  1094. shells/1
  1095. ::::::::::::::
  1096. Date: Thu, 13 Sep 84 12:49:57 edt
  1097. From: allegra!vax135!cornell!tesla!mac (Michael Mc Namara)
  1098. To: cornell!vax135!houxm!mhuxl!ulysses!allegra!resonex!nancy
  1099. Subject: Cute cshell - sh scripts
  1100.  
  1101.     If your are like most UNIX systems, you have a plethora of different
  1102. terminals that  your system  is supposed to support.  Sure, with termcap
  1103. and terminfo, and programs written to use them, the interface gets easier.
  1104. If you only ever login to one particular terminal, you can 
  1105.  
  1106. set term = "vt131"
  1107.  
  1108. or 
  1109.  
  1110. TERM=vt131
  1111. export TERM
  1112.  
  1113. in your .login or .profile.
  1114.  
  1115. But what if you,  or some of your users,  drift  around using different
  1116. terminal types-- You have a terminal room with many different terminals.
  1117.  
  1118. Here is a set of shell scripts & C programs that use the "echo terminal
  1119. type" command that many terminals support, to do automatic terminal type
  1120. identification and setting:  (of course I've only made it work for  the 
  1121. terminals we have here at Cornell, and some day I should write more of it
  1122. in C...)
  1123.  
  1124.     This one is written for cshell:
  1125.  
  1126. ##########################################
  1127. #    Identify and set terminal type (csh)#
  1128. ##########################################
  1129. set noglob
  1130. echo Please wait...
  1131. stty cbreak -echo
  1132. # this sequence will cause all terminals we have to echo something
  1133. # except for adm's; those users are told to hit 'a' when they see
  1134. # please wait
  1135. echo ' CZ[c'
  1136. sleep 1      
  1137. # this calls a c program to grab the id string from the terminal 
  1138. # program is included later...
  1139. set type = `/usr/new/rin.login`
  1140. stty -cbreak echo new crt
  1141. #########################
  1142. # the or in the vt100 terminal type is because vt100's respond
  1143. # to both ^[Z and ^[[c, but DEC threatens to eliminate one of 
  1144. # the responces (I forget which).. The extra stty back you see
  1145. # with DG terminals (Data General) is because their backspace is
  1146. # ^Y instead of ^H ( Home on DG terminals) This involves a modification
  1147. # of stty, which you would care about only if you have them--Write to me.
  1148. ##################
  1149. if ( $type == "[?1;0c" || $type == "[?1;0c[?1;0c" ) then
  1150.      set term = vt100
  1151.      echo "VT101"                            
  1152. else if ( $type == "[?1;2c" || $type == "[?1;2c[?1;2c" ) then
  1153.      set term = vt100
  1154.      echo "VT100"
  1155. else if ( $type == "[?1;11c[?1;11c") then
  1156.      set term = ct500
  1157.      echo "[7mCIT - 500[m"
  1158. else if ( $type == "[?12;5;0;102c" ) then
  1159.      set term = vt100
  1160.      echo "VT125"
  1161. else if ($type == "[?1;2c[?1;2c") then
  1162.      set term = vt100
  1163.      echo "VT100, with Selenar Graphics"
  1164. else if ( $type == "o#\!R" ) then
  1165.      set term = dg200
  1166.      stty stop undef start undef back  
  1167.      echo "DDG200E"
  1168. else if ( $type == "o#'C3" ) then
  1169.      set term = dg450
  1170.      stty back  
  1171.      echo "FS11BFS00 DATA GENERAL DASHER D450" 
  1172. else if ( $type == "o#'K3" ) then 
  1173.      set term = dg450
  1174.      stty back  
  1175.      echo "FS11BFS00 DATA GENERAL DASHER D450" 
  1176. else if ( $type == "/K" ) then
  1177.      set term = vt52
  1178.      echo "Visual 50"
  1179. else if ( $type =~ "\\4*" ) then
  1180.      set term = hp2621          
  1181.      echo HP2621
  1182. else if ( $type =~ "a" ) then
  1183.      set term = adm3a
  1184.      echo "adm3a"
  1185. else if ($type == "50" ) then
  1186.      set term = w50
  1187.      echo "WYSE50"
  1188. else
  1189. # Ask user for terminal type -- for some reason the above didn't work
  1190. set no_name_yet=1
  1191. set no_name_yet = 1;
  1192. while( $no_name_yet )
  1193.    echo -n "Please enter terminal type (hit return for menu) "
  1194.    set ttyname = ($< );
  1195.    switch( $ttyname )
  1196.    case d450:
  1197.    case dg450:
  1198.       set term=dg450;
  1199.       stty back 
  1200.       set no_name_yet = 0;
  1201.       breaksw;
  1202.    case vt100:
  1203.       set term=vt100;
  1204.       set no_name_yet = 0;
  1205.       breaksw;
  1206.    case v50:
  1207.    case vt52:
  1208.       set term=vt52;
  1209.       set no_name_yet = 0;
  1210.       breaksw;
  1211.    case hp2621:
  1212.    case hp:
  1213.       set term=hp2621;
  1214.       set no_name_yet = 0;
  1215.       breaksw;
  1216.    case wyse50:
  1217.       set term=w100;
  1218.       set no_name_yet = 0;
  1219.       breaksw;
  1220.    case adm5:
  1221.       set term=adm5;  
  1222.       set no_name_yet = 0;
  1223.       breaksw;
  1224.    case adm3+:                 
  1225.    case adm3:
  1226.    case adm3a:
  1227.       set term=adm3+;
  1228.       set no_name_yet = 0;
  1229.    case d200:
  1230.    case dg200:
  1231.       set term=dg200;
  1232.       stty stop undef start undef back ;
  1233.       set no_name_yet = 0;
  1234.       breaksw;
  1235.    case other:
  1236.       echo -n "Enter terminal name: "
  1237.       set term=($< );
  1238.       set no_name_yet = 0;
  1239.       breaksw;
  1240.    case '':
  1241.       echo Terminal abbreviations are:
  1242.       echo "Dasher 450 : dg450"
  1243.       echo "Dasher 200 : dg200"
  1244.       echo "Visual 50  : v50"
  1245.       echo "VT100      : vt100"
  1246.       echo "HP 2621    : hp2621"
  1247.       echo "ADM5       : adm5"
  1248.       echo "ADM3+      : adm3+"
  1249.       echo "Use 'other' to specify terminals not on this menu"
  1250.       breaksw;
  1251.    default:
  1252.       echo "I didn't understand that. Hit return for a menu."
  1253.    endsw
  1254. end
  1255. unset no_name_yet
  1256. unset ttyname
  1257. endif
  1258. stty -cbreak
  1259. stty echo
  1260. unset noglob
  1261.  
  1262. Ok, This one is used for Bourne shell lovers:  (I used /bin/test because
  1263. one user had an executable file called test somewhere in his path ahead
  1264. of where this program lived...That one took days to track down...)
  1265.  
  1266.  
  1267. echo "Please Wait..."
  1268. stty start  stop   crt new back  -echo cbreak
  1269. echo ' CZ[c'
  1270. sleep 1
  1271. TYPE=`/usr/new/rin.login`
  1272. stty echo -cbreak
  1273. if ( /bin/test \( $TYPE = "[?1;0c" \) -o \( $TYPE = "[?1;0c[?1;0c" \) ) then
  1274.      TERM=vt100
  1275.      echo "[7mVT101[m" 
  1276. elif ( /bin/test \( $TYPE = "[?1;2c" \) -o \( $TYPE = "[?1;2c[?1;2c" \)  ) then
  1277.      TERM=vt100
  1278.      echo "#3[7mVT100[m"
  1279.      echo "#4?[7mVT100[m"
  1280. elif ( /bin/test  $TYPE = "[?1;11c[?1;11c") then
  1281.      TERM=ct500
  1282.      echo "CT 500"
  1283. elif ( /bin/test  $TYPE = "o#!R" ) then
  1284.      TERM=dg200
  1285.      stty stop undef
  1286.      stty start undef
  1287.      stty crt
  1288.      stty back 
  1289.      echo "D DATA GENERAL DASHER D200E"
  1290. elif ( /bin/test $TYPE = "o#'C3" )  then
  1291.      TERM=dg450
  1292.      stty crt   
  1293.      stty back 
  1294.      echo "FS11BFS00 DATA GENERAL DASHER D450"
  1295. elif ( /bin/test $TYPE = "/K" ) then
  1296.      TERM=vt52
  1297.      echo "UVisual 50T"
  1298. elif ( /bin/test $TYPE = "50" ) then
  1299.      TERM=w50
  1300.      clear
  1301.      echo "WYSE 50"
  1302. elif ( /bin/test $TYPE = "\4088000" ) then
  1303.      TERM=hp2621
  1304.      echo HP2621
  1305. elif ( /bin/test $TYPE = "a" ) then
  1306.      TERM=adm3a
  1307.      echo ADM3a
  1308. else
  1309.      stty start 
  1310.      stty stop  
  1311.      stty new crt
  1312.      set no_name_yet=1
  1313. echo
  1314. while ($no_name_yet) do {
  1315.   echo
  1316.   echo Which terminal do you have?
  1317.   echo       Hit return for a menu.
  1318.   read INP
  1319.   case $INP
  1320.     in
  1321. 100 | v | vt100) {
  1322.                   TERM=vt100
  1323.                   break
  1324.              } ;;
  1325. adm5)            {
  1326.                  TERM=adm5
  1327.                  break
  1328.              } ;;
  1329. adm3+)           {
  1330.                  TERM=adm3+
  1331.                  break
  1332.              } ;;
  1333. 450 | dg450 | d450)  {
  1334.                   TERM=dg450
  1335.                   stty back 
  1336.                   break
  1337.              } ;;
  1338. 200 | dg200 | d200)  {
  1339.                   TERM=dg200
  1340.                   stty stop undef
  1341.                   stty start undef
  1342.                   stty back 
  1343.                   break
  1344.              }  ;;
  1345.  50 | vt52 | v50)   { 
  1346.                   TERM=vt52
  1347.                   break
  1348.              } ;;
  1349.  2621 | hp2621 | hp) {
  1350.                   TERM=hp2621
  1351.                   break
  1352.              } ;;
  1353.       other) {
  1354.                   echo -n Enter terminal name:
  1355.                   read tname
  1356.                   TERM=$tname
  1357.                   break
  1358.              } ;;
  1359.  ''|?|help)  {    echo Terminal abbreviations are:
  1360.                   echo 
  1361.                   echo Dasher 450:  dg450
  1362.                   echo Dasher 200:  dg200
  1363.                   echo Visual  50:  vt52
  1364.                   echo VT100     :  vt100
  1365.                   echo HP 2621   :  hp2621
  1366.                   echo ADM3+     :  adm3+
  1367.                   echo ADM5      :  adm5
  1368.                   echo "Use 'other' to specify other terminals."
  1369.                   echo
  1370.              } ;;
  1371.         * )  {   echo "I did not understand that."
  1372.              } ;;
  1373.   esac
  1374.   }
  1375. done
  1376. fi
  1377. export TERM
  1378.  
  1379. *********
  1380. And here is the c program that read's in the terminal ID string:
  1381.  
  1382.  
  1383. /* rin -- read in a char string which may not be terminated */
  1384. char buf[256];
  1385. int n;
  1386. main ()
  1387. {
  1388. n = read(0,buf,256);
  1389. write(1,buf,n);
  1390. printf("\n");
  1391. }
  1392.  
  1393. ***************
  1394.  
  1395.  
  1396.         Use them, abuse them.  Of course you have to paw through
  1397. your terminal manuanls to discover what (if any) string they respond to,
  1398. and test for the response accordingly...
  1399.  
  1400.                                         ---MAC
  1401.  
  1402.  
  1403.  
  1404. ::::::::::::::
  1405. shells/2
  1406. ::::::::::::::
  1407. From: hplabs!azure!billp
  1408. To: tektronix!hplabs!resonex!nancy
  1409. Date: Thursday, 13 Sep 84 09:23:49 PDT
  1410. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  1411.  
  1412. Here are some that I like and use a lot.  'del' and 'undelete' are just two
  1413. links to the same file.  This way if somebody copies one, they get the
  1414. other too
  1415. -------------------------------------------------------------------------------
  1416. ::::::::::::::
  1417. : mv
  1418. ::::::::::::::
  1419. : 'prompts if the destination file already exists'
  1420. /bin/mv -i $*
  1421. -------------------------------------------------------------------------------
  1422. ::::::::::::::
  1423. : cp
  1424. ::::::::::::::
  1425. : 'prompts if the destination file already exists'
  1426. /bin/cp -i $*
  1427. -------------------------------------------------------------------------------
  1428. ::::::::::::::
  1429. : del, undelete
  1430. ::::::::::::::
  1431. : '"del" throws files into the waste basket'
  1432. : 'files preceded by "," are automagically removed after 7 days'
  1433. : '"undelete" pulls files out of the waste basket'
  1434. : 'if invoked without an argument, both commands list the contents of the'
  1435. : 'waste basket.'
  1436.  
  1437. case $0 in
  1438. *del)
  1439.     if test -z "$1"
  1440.     then
  1441.     ls -lus $HOME/.waste_basket
  1442.     else
  1443.     for i
  1444.     do
  1445.         echo -n "deleting "
  1446.         tmp=`basename $i`
  1447.         /bin/mv -i $i $HOME/.waste_basket/,$tmp
  1448.         echo $i
  1449.     done
  1450.     fi;;
  1451.  
  1452. *undelete)
  1453.     if test -z "$1"
  1454.     then
  1455.     ls -lus $HOME/.waste_basket
  1456.     else
  1457.     for i
  1458.     do
  1459.         echo -n "recovering "
  1460.         tmp=`basename $i`
  1461.         /bin/mv -i $HOME/.waste_basket/,$tmp $i
  1462.         echo $i
  1463.     done
  1464.     fi;;
  1465. esac
  1466. -------------------------------------------------------------------------------
  1467. ::::::::::::::
  1468. : vi
  1469. ::::::::::::::
  1470. : 'backs up file(s) before editing them'
  1471. : 'files preceded by "," are automagically removed after 7 days'
  1472. for i
  1473. do
  1474.     if test -f $i
  1475.     then
  1476.     echo -n "backing up "
  1477.     tmp=`basename $i`
  1478.     /bin/cp -i $i $HOME/.vi_backup/,$tmp
  1479.     echo $i
  1480.     fi
  1481. done
  1482. /usr/ucb/vi $*
  1483. -------------------------------------------------------------------------------
  1484.  
  1485.     Bill Pfeifer
  1486. {ucbvax,decvax,ihnp4,allegra,uw-beaver,hplabs} !tektronix!tekmdp!billp
  1487.  
  1488. ::::::::::::::
  1489. shells/3
  1490. ::::::::::::::
  1491. Date: Thu, 13 Sep 84 13:58:09 pdt
  1492. From: turtlevax!ken (Ken Turkowski)
  1493. To: resonex!nancy
  1494. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  1495.  
  1496. You asked for it, you've got it!  Here's ALL of my personal nifties:
  1497.             Ken
  1498. **************************************************
  1499.  
  1500. echo x - bin
  1501. mkdir bin
  1502. echo x - bin/CC
  1503. cat >bin/CC <<'!Funky!Stuff!'
  1504. #
  1505. set outname=a.out
  1506. foreach file ($argv)
  1507.     if ("$file" =~ *.[cso]) then
  1508.     set outname=$file:r
  1509.         break
  1510.     endif
  1511. end
  1512. echo cc -o $outname $*
  1513. exec cc -o $outname $*
  1514. !Funky!Stuff!
  1515. echo x - bin/appt
  1516. cat >bin/appt <<'!Funky!Stuff!'
  1517. #
  1518. set notetype=$0
  1519. set notetype=$notetype:t
  1520. set notefile=~/.$notetype
  1521. # if ($notetype == appt) then
  1522. #     set notetype=appointment
  1523. #     set notefile=~/calendar
  1524. # endif
  1525.  
  1526. if ($#argv == 0) then
  1527.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  1528.     echo ' ' >> $notefile
  1529.     exec cat >> $notefile
  1530. endif
  1531.  
  1532. switch ($1)
  1533.     case -:
  1534.     exec vi $notefile
  1535.     case -rm:
  1536.     cat /dev/null > $notefile
  1537.     exec echo The ${notetype}s are removed.
  1538.     case -what:
  1539.     exec cat $notefile
  1540.     default:
  1541.     echo '' >> $notefile
  1542.     echo "$*" >> $notefile
  1543. endsw
  1544. !Funky!Stuff!
  1545. echo x - bin/asfix
  1546. cat >bin/asfix <<'!Funky!Stuff!'
  1547. case $# in
  1548.     0)
  1549.     file=/tmp/afix$$
  1550.     trap "cat $file; rm $file; exit" 0
  1551.     trap "rm $file; exit" 3 9
  1552.     cat > $file ;;
  1553.     1)
  1554.     file=$1 ;;
  1555.     *)
  1556.     echo Usage `basename $0` ' [ <file> ]' ;;
  1557. esac
  1558. ed - $file << EOF
  1559. v/[:\.]/s/^/    /
  1560. g/:./s/:/:    /
  1561. wq
  1562. EOF
  1563. !Funky!Stuff!
  1564. echo x - bin/atcat
  1565. cat >bin/atcat <<'!Funky!Stuff!'
  1566. #
  1567. if ($#argv < 2) then
  1568.     set cmd=$0
  1569.     echo Usage: "$cmd:t <time> <word> [ <word> ... ]"
  1570.     exit
  1571. endif
  1572. set atcmd="echo $argv[2-] > `tty`"
  1573. at $1 << EOF
  1574. $atcmd
  1575. EOF
  1576. !Funky!Stuff!
  1577. echo x - bin/atecho
  1578. cat >bin/atecho <<'!Funky!Stuff!'
  1579. #
  1580. if ($#argv < 2) then
  1581.     set cmd=$0
  1582.     echo Usage: "$cmd:t <time> <word> [ <word> ... ]"
  1583.     exit
  1584. endif
  1585. set atcmd="echo $argv[2-] > `tty`"
  1586. at $1 << EOF
  1587. $atcmd
  1588. EOF
  1589. !Funky!Stuff!
  1590. echo x - bin/beautify
  1591. cat >bin/beautify <<'!Funky!Stuff!'
  1592. #
  1593. set TMP=/tmp/cb$$
  1594. foreach file (argv)
  1595.     echo Beautifying $file:
  1596.     cb < $file > $TMP
  1597.     cat $TMP > $file
  1598. end
  1599. rm $TMP
  1600. !Funky!Stuff!
  1601. echo x - bin/blankclean
  1602. cat >bin/blankclean <<'!Funky!Stuff!'
  1603. sed -e 's/^    $//' -e 's/ *$//' $*
  1604. !Funky!Stuff!
  1605. echo x - bin/bphone
  1606. cat >bin/bphone <<'!Funky!Stuff!'
  1607. phonefile=$HOME/.`basename $0`s
  1608.  
  1609. echo ' '
  1610.  
  1611. case $# in
  1612.     0)
  1613.     ed - $phonefile << EOF
  1614. g/./s/$/\\
  1615. /
  1616. g/    /s//\\
  1617. /g
  1618. g/;/s//    /g
  1619. 1,\$p
  1620. q
  1621. EOF
  1622.     exit ;;
  1623. esac
  1624.  
  1625. case $1 in
  1626.     -)
  1627.     chmod 644 $phonefile
  1628.     vi $phonefile
  1629.     chmod 444 $phonefile
  1630.     exit ;;
  1631. esac
  1632.  
  1633. trap "rm /tmp/data$$; exit" 0 2
  1634. for name
  1635. do
  1636.     grep -y "$name" $phonefile >> /tmp/data$$
  1637. done
  1638. ed - /tmp/data$$ << EOF
  1639. g/./s/$/\\
  1640. /
  1641. g/    /s//\\
  1642. /g
  1643. g/;/s//    /g
  1644. 1,\$p
  1645. q
  1646. EOF
  1647. !Funky!Stuff!
  1648. echo x - bin/catalog
  1649. cat >bin/catalog <<'!Funky!Stuff!'
  1650. # catalog - produce complete file structure list from directory
  1651. # Parameters:     1: directory name (optional)
  1652. #         2: indentation string (empty on first call)
  1653. # Produces on standard output the file structure emanating from
  1654. #   the current directory.  Each descent into a subdirectory
  1655. #    is indicated by further indentation.  Directories are indicated
  1656. #    by surrounding [], and executable files are prefaced with a *.
  1657. if ( $#argv == 0) then
  1658.    echo "file structure from directory `pwd`"
  1659.    date
  1660.    echo ''
  1661. else
  1662.    cd $1
  1663. endif
  1664. foreach i ( * )
  1665.    if ( -d $i ) then
  1666.      echo "${2}[ $i ]"
  1667.      $0 $i "$2  . "
  1668.    endif
  1669.      if ( "$i" != '*' ) then
  1670.         if ( -x $i ) then
  1671.            echo "${2} *$i "
  1672.         else
  1673.            echo "${2}  $i "
  1674.         endif
  1675.      endif
  1676.    endif
  1677. end
  1678. !Funky!Stuff!
  1679. echo x - bin/circum
  1680. cat >bin/circum <<'!Funky!Stuff!'
  1681. there=$1
  1682. shift
  1683. otherstuff="$*"
  1684. back=`whoami`
  1685. last=`hostname`
  1686. IFS='     !    
  1687. '
  1688. for link in $there
  1689. do
  1690.     back="$last!$back"
  1691.     last=$link
  1692. done
  1693. IFS='     
  1694. '
  1695. echo mail $there!$back
  1696. (date; echo "$otherstuff") | mail -s "Circumlocution to $last" $there!$back
  1697. !Funky!Stuff!
  1698. echo x - bin/comfmt
  1699. cat >bin/comfmt <<'!Funky!Stuff!'
  1700. exec fmt | \
  1701. sed -e '1s/^\([     ]*\)/\1\/\* /' -e '2,$s/^\([     ]*\)/\1 \* /' -e '${P
  1702. s/\*.*/*\//
  1703. }'
  1704. !Funky!Stuff!
  1705. echo x - bin/comstrip
  1706. cat >bin/comstrip <<'!Funky!Stuff!'
  1707. exec sed -e 's/\/\*//' -e 's/\*\///' -e 's/^[     ]*\** *//'
  1708. !Funky!Stuff!
  1709. echo x - bin/decvert
  1710. cat >bin/decvert <<'!Funky!Stuff!'
  1711. #
  1712. if ($#argv == 0) then
  1713.     set args=`cat`
  1714.     if ($#args != 0) $0 $args
  1715.     exit
  1716. endif
  1717.  
  1718. foreach hexnum ($argv)
  1719. dc << EOF
  1720. 16i
  1721. ${hexnum}p
  1722. EOF
  1723. end
  1724. !Funky!Stuff!
  1725. echo x - bin/f77
  1726. cat >bin/f77 <<'!Funky!Stuff!'
  1727. PATH=/usr/bin
  1728. SPECLIB=/usr/ken/cmd/lib/libc.a
  1729. exec f77 "$@" $SPECLIB
  1730. !Funky!Stuff!
  1731. echo x - bin/famove
  1732. cat >bin/famove <<'!Funky!Stuff!'
  1733. #
  1734. if ($#argv != 2) then
  1735.     echo Usage: $0 '<source family root> <destination family root>'
  1736.     exit
  1737. endif
  1738. foreach file ($1.*)
  1739.     set suffix=`expr $file : "$1\.\(.*\)"`
  1740.     echo mv $file $2.$suffix
  1741.     mv $file $2.$suffix
  1742. end
  1743. if (-e $1) then
  1744.     echo mv $1 $2
  1745.     mv $1 $2
  1746. endif
  1747. !Funky!Stuff!
  1748. echo x - bin/gredit
  1749. cat >bin/gredit <<'!Funky!Stuff!'
  1750. #
  1751. set CAESAR=/mnt/cad/bin/caesar
  1752. set SEARCHPATH=(-p ::/usr/ken/caesar/symlib)
  1753. set COLORMAP=(-c mumap.cmap)
  1754. set GRTERM=ttyh7
  1755. set caesarfile=()
  1756. foreach parm ($argv)
  1757.     if ($?flag) then
  1758.     switch ($flag)
  1759.         case g:
  1760.         set GRTERM=$parm
  1761.         breaksw
  1762.         case p:
  1763.         set SEARCHPATH=(-p "$parm")
  1764.         breaksw
  1765.         case R:
  1766.         set SEARCHPATH=($SEARCHPATH:$parm)
  1767.         breaksw
  1768.         case c:
  1769.         set COLORMAP=(-c $parm)
  1770.         breaksw
  1771.     endsw
  1772.     unset flag
  1773.     continue
  1774.     endif
  1775.     if ($parm =~ -*) then
  1776.     switch ($parm)
  1777.         case -g:
  1778.         set flag=g
  1779.         continue
  1780.         case -p:
  1781.         set flag=p
  1782.         continue
  1783.         case -P:
  1784.         set SEARCHPATH=()
  1785.         continue
  1786.         case -R:
  1787.         set flag=R
  1788.         continue
  1789.         case -C:
  1790.         set COLORMAP=()
  1791.         continue
  1792.         case -c:
  1793.         set flag=c
  1794.         continue
  1795.     endsw
  1796.     else
  1797.     set caesarfile=($caesarfile $parm)
  1798.     endif
  1799. end
  1800. onintr -
  1801. $CAESAR -g $GRTERM $SEARCHPATH $COLORMAP $caesarfile
  1802. !Funky!Stuff!
  1803. echo x - bin/grindall
  1804. cat >bin/grindall <<'!Funky!Stuff!'
  1805. #
  1806. set flags=
  1807. set fileargs=
  1808. onintr cleanup
  1809. foreach file ($argv)
  1810.     if ($file =~ -*) then
  1811.     if ($file == -t) then
  1812.         set stdout
  1813.     else
  1814.         set flags=($flags $file)
  1815.     endif
  1816.     else
  1817.     set fileargs=($fileargs $file)
  1818.     endif
  1819. end
  1820.  
  1821. if ($?stdout) then
  1822.     foreach file ($fileargs)
  1823.     vgrind -t $flags $file
  1824.     end
  1825. else
  1826.     foreach file ($fileargs)
  1827.     vgrind -t $flags $file >> /usr/tmp/grind$$
  1828.     end
  1829.     vpr -T $fileargs[1] -t /usr/tmp/grind$$
  1830. endif
  1831.  
  1832. cleanup:
  1833. rm /usr/tmp/grind$$
  1834. !Funky!Stuff!
  1835. echo x - bin/hardasm
  1836. cat >bin/hardasm <<'!Funky!Stuff!'
  1837. #
  1838. grasm -1 -l -x $* |& pr -f -h "grasm -l -x $*" | vpr -l
  1839. !Funky!Stuff!
  1840. echo x - bin/hexvert
  1841. cat >bin/hexvert <<'!Funky!Stuff!'
  1842. #
  1843. if ($#argv == 0) then
  1844.     set args=`cat`
  1845.     if ($#args != 0) $0 $args
  1846.     exit
  1847. endif
  1848.  
  1849. foreach decnum ($argv)
  1850. dc << EOF
  1851. 16o
  1852. ${decnum}p
  1853. EOF
  1854. end
  1855. !Funky!Stuff!
  1856. echo x - bin/job
  1857. cat >bin/job <<'!Funky!Stuff!'
  1858. PATH=/usr/ken/cmd/bin:/usr/ucb:/bin:/usr/bin
  1859. case $# in
  1860.     0)
  1861.     exec echo Usage: `basename $0` '-;' or $0 '<job description>' ;;
  1862. esac
  1863. case $1 in
  1864.     -)
  1865.     exec ex $HOME/.joblog ;;
  1866.     -h | -hr | -hrs)
  1867.     shift
  1868.     hrs=$1
  1869.     shift
  1870.     exec echo '   job:' $hrs hours # $* >> $HOME/.joblog ;;
  1871.     -tail)
  1872.     exec tail -22 $HOME/.joblog ;;
  1873.     -today)
  1874.     {
  1875.         while read line
  1876.         do
  1877.         case $line in
  1878.             *login*)
  1879.             login="$line" ;;
  1880.         esac
  1881.         done
  1882.         echo -n "$login" "for "
  1883.         diffdate "$login" "`date`"
  1884.     } < $HOME/.joblog ;;
  1885.     -login)
  1886.     echo ' login:' "`date`" >> $HOME/.joblog ;;
  1887.     -summary)
  1888.     cat $HOME/.joblog |
  1889.         while read line
  1890.         do
  1891.         case $line in
  1892.             *login*)
  1893.             login="$line" ;;
  1894.             *logout*)
  1895.             logout="$line"
  1896.             echo -n "$login" "for "
  1897.             diffdate "$login" "$logout"
  1898.         esac
  1899.         done ;;
  1900.     *)
  1901.     exec echo '   job:' "`date`" # $* >> $HOME/.joblog ;;
  1902. esac
  1903. !Funky!Stuff!
  1904. echo x - bin/ledger
  1905. cat >bin/ledger <<'!Funky!Stuff!'
  1906. #
  1907. set notetype=$0
  1908. set notetype=$notetype:t
  1909. set notefile=~/.$notetype
  1910. # if ($notetype == appt) then
  1911. #     set notetype=appointment
  1912. #     set notefile=~/calendar
  1913. # endif
  1914.  
  1915. if ($#argv == 0) then
  1916.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  1917.     echo ' ' >> $notefile
  1918.     exec cat >> $notefile
  1919. endif
  1920.  
  1921. switch ($1)
  1922.     case -:
  1923.     exec vi $notefile
  1924.     case -rm:
  1925.     cat /dev/null > $notefile
  1926.     exec echo The ${notetype}s are removed.
  1927.     case -what:
  1928.     exec cat $notefile
  1929.     default:
  1930.     echo '' >> $notefile
  1931.     echo "$*" >> $notefile
  1932. endsw
  1933. !Funky!Stuff!
  1934. echo x - bin/lstree
  1935. cat >bin/lstree <<'!Funky!Stuff!'
  1936. #
  1937. if ($#argv == 0) then
  1938.     set root=.
  1939. else
  1940.     set root=($*)
  1941. endif
  1942. exec find $root -print | sort | sed -e 's/[^ \/]*\//    /g'
  1943. !Funky!Stuff!
  1944. echo x - bin/match
  1945. cat >bin/match <<'!Funky!Stuff!'
  1946. cat $2 |
  1947. while read x
  1948. do
  1949.     for word in $x
  1950.     do
  1951.     case $word in
  1952.         $1)
  1953.         echo $word ;;
  1954.     esac
  1955.     done
  1956. done
  1957. !Funky!Stuff!
  1958. echo x - bin/narrow
  1959. cat >bin/narrow <<'!Funky!Stuff!'
  1960. echo \!
  1961. !Funky!Stuff!
  1962. echo x - bin/outmesg
  1963. cat >bin/outmesg <<'!Funky!Stuff!'
  1964. #
  1965. set notetype=$0
  1966. set notetype=$notetype:t
  1967. set notefile=~/.$notetype
  1968. # if ($notetype == appt) then
  1969. #     set notetype=appointment
  1970. #     set notefile=~/calendar
  1971. # endif
  1972.  
  1973. if ($#argv == 0) then
  1974.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  1975.     echo ' ' >> $notefile
  1976.     exec cat >> $notefile
  1977. endif
  1978.  
  1979. switch ($1)
  1980.     case -:
  1981.     exec vi $notefile
  1982.     case -rm:
  1983.     cat /dev/null > $notefile
  1984.     exec echo The ${notetype}s are removed.
  1985.     case -what:
  1986.     exec cat $notefile
  1987.     default:
  1988.     echo '' >> $notefile
  1989.     echo "$*" >> $notefile
  1990. endsw
  1991. !Funky!Stuff!
  1992. echo x - bin/path
  1993. cat >bin/path <<'!Funky!Stuff!'
  1994. IFS="${IFS}:"
  1995. for cmddir in $PATH
  1996. do
  1997.     test -s $cmddir/$1 && echo "    $cmddir/$1"
  1998. done
  1999. !Funky!Stuff!
  2000. echo x - bin/pphone
  2001. cat >bin/pphone <<'!Funky!Stuff!'
  2002. phonefile=$HOME/.`basename $0`s
  2003.  
  2004. echo ' '
  2005.  
  2006. case $# in
  2007.     0)
  2008.     ed - $phonefile << EOF
  2009. g/./s/$/\\
  2010. /
  2011. g/    /s//\\
  2012. /g
  2013. g/;/s//    /g
  2014. 1,\$p
  2015. q
  2016. EOF
  2017.     exit ;;
  2018. esac
  2019.  
  2020. case $1 in
  2021.     -)
  2022.     chmod 644 $phonefile
  2023.     vi $phonefile
  2024.     chmod 444 $phonefile
  2025.     exit ;;
  2026. esac
  2027.  
  2028. trap "rm /tmp/data$$; exit" 0 2
  2029. for name
  2030. do
  2031.     grep -y "$name" $phonefile >> /tmp/data$$
  2032. done
  2033. ed - /tmp/data$$ << EOF
  2034. g/./s/$/\\
  2035. /
  2036. g/    /s//\\
  2037. /g
  2038. g/;/s//    /g
  2039. 1,\$p
  2040. q
  2041. EOF
  2042. !Funky!Stuff!
  2043. echo x - bin/progression
  2044. cat >bin/progression <<'!Funky!Stuff!'
  2045. last=
  2046. for backup in $1_??
  2047. do
  2048.     case $last in
  2049.     "")
  2050.         last=$backup
  2051.         continue;
  2052.     esac
  2053.     echo ''
  2054.     echo From $last to $backup:
  2055.     diff $last $backup
  2056.     last=$backup
  2057. done
  2058. echo ''
  2059. echo From $last to $1:
  2060. diff $last $1
  2061. !Funky!Stuff!
  2062. echo x - bin/query
  2063. cat >bin/query <<'!Funky!Stuff!'
  2064. #
  2065. set notetype=$0
  2066. set notetype=$notetype:t
  2067. set notefile=~/.$notetype
  2068. # if ($notetype == appt) then
  2069. #     set notetype=appointment
  2070. #     set notefile=~/calendar
  2071. # endif
  2072.  
  2073. if ($#argv == 0) then
  2074.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  2075.     echo ' ' >> $notefile
  2076.     exec cat >> $notefile
  2077. endif
  2078.  
  2079. switch ($1)
  2080.     case -:
  2081.     exec vi $notefile
  2082.     case -rm:
  2083.     cat /dev/null > $notefile
  2084.     exec echo The ${notetype}s are removed.
  2085.     case -what:
  2086.     exec cat $notefile
  2087.     default:
  2088.     echo '' >> $notefile
  2089.     echo "$*" >> $notefile
  2090. endsw
  2091. !Funky!Stuff!
  2092. echo x - bin/releave
  2093. cat >bin/releave <<'!Funky!Stuff!'
  2094. #
  2095. set tty=`tty`
  2096. set tty=`expr $tty : '.*tty\(.*\)'`
  2097. set leaveproc=`ps gt$tty | grep -w leave`
  2098. kill -9 $leaveproc[1]
  2099. date
  2100. leave $*
  2101. !Funky!Stuff!
  2102. echo x - bin/reminder
  2103. cat >bin/reminder <<'!Funky!Stuff!'
  2104. #
  2105. set notetype=$0
  2106. set notetype=$notetype:t
  2107. set notefile=~/.$notetype
  2108. # if ($notetype == appt) then
  2109. #     set notetype=appointment
  2110. #     set notefile=~/calendar
  2111. # endif
  2112.  
  2113. if ($#argv == 0) then
  2114.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  2115.     echo ' ' >> $notefile
  2116.     exec cat >> $notefile
  2117. endif
  2118.  
  2119. switch ($1)
  2120.     case -:
  2121.     exec vi $notefile
  2122.     case -rm:
  2123.     cat /dev/null > $notefile
  2124.     exec echo The ${notetype}s are removed.
  2125.     case -what:
  2126.     exec cat $notefile
  2127.     default:
  2128.     echo '' >> $notefile
  2129.     echo "$*" >> $notefile
  2130. endsw
  2131. !Funky!Stuff!
  2132. echo x - bin/reremind
  2133. cat >bin/reremind <<'!Funky!Stuff!'
  2134. #
  2135. set tty=`tty`
  2136. set tty=`expr $tty : '.*tty\(.*\)'`
  2137. set leaveproc=`ps gt$tty | awk '$5 ~ /^remind$/ { print $1 }'`
  2138. if ($#leaveproc > 1) echo $#leaveproc reminds were running
  2139. kill -9 $leaveproc
  2140. date
  2141. if ($#argv <= 1) then
  2142.     remind $*
  2143. else
  2144.     set time=$1
  2145.     shift
  2146.     remind $time "$*"
  2147. endif
  2148. !Funky!Stuff!
  2149. echo x - bin/restore
  2150. cat >bin/restore <<'!Funky!Stuff!'
  2151. # Truncate filename if necessary
  2152. set file=$1
  2153. if (`expr $file:t : '.*'` >= 11) then
  2154.     set savename=`expr $file : '\(.*\)'$file:t`
  2155.     set savename=$savename`expr $file:t : '\(...........\)'`
  2156. else
  2157.     set savename=$file
  2158. endif
  2159.  
  2160. switch ($#argv)
  2161.     case 1:
  2162.     set nonomatch
  2163.     set backup=(${savename}_[0-9][0-9])
  2164.     if ("$backup" == "${savename}_[0-9][0-9]") then
  2165.         echo Error: No backups found for $file
  2166.         exit
  2167.     endif
  2168.     set backup=$backup[$#backup]
  2169.     echo No backup number specified. Using latest: $backup
  2170.     breaksw
  2171.     case 2:
  2172.     set backup=${savename}_$2
  2173.     breaksw
  2174.     default:
  2175.     exec echo Usage: `basename $0` '<file>' '[<backup number>]'
  2176. endsw
  2177.  
  2178. if ( { cp $backup $file } ) then
  2179.     echo $file restored from $backup.
  2180.     echo -n Do you wish to keep "$backup? "
  2181.     set response=$<
  2182.     if ($response !~ y*) then
  2183.     rm $backup
  2184.     endif
  2185. endif
  2186. !Funky!Stuff!
  2187. echo x - bin/rot13
  2188. cat >bin/rot13 <<'!Funky!Stuff!'
  2189. tr "A-Za-z" "N-ZA-Mn-za-m"
  2190. !Funky!Stuff!
  2191. echo x - bin/shufcol
  2192. cat >bin/shufcol <<'!Funky!Stuff!'
  2193. trap 'rm /tmp/$$.*; exit' 0 2
  2194. cat > /tmp/$$.0
  2195. i=1
  2196. for cols
  2197. do
  2198.     cut -f$cols < /tmp/$$.0 > /tmp/$$.$i
  2199.     filelist="$filelist /tmp/$$.$i"
  2200.     i=`expr $i + 1`
  2201. done
  2202. paste $filelist
  2203. !Funky!Stuff!
  2204. echo x - bin/signature
  2205. cat >bin/signature <<'!Funky!Stuff!'
  2206. PATH=/bin:/usr/bin
  2207. cat
  2208. echo --
  2209. cat $HOME/.signature
  2210. !Funky!Stuff!
  2211. echo x - bin/swab
  2212. cat >bin/swab <<'!Funky!Stuff!'
  2213. #
  2214. if ($#argv == 0) then
  2215.     dd conv=swab
  2216. else
  2217.     onintr cleanup
  2218.     foreach file ($argv)
  2219.     cp $file /tmp/swab$$
  2220.     dd if=/tmp/swab$$ of=$file conv=swab
  2221.     end
  2222.     cleanup:
  2223.     rm /tmp/swab$$
  2224. endif
  2225. !Funky!Stuff!
  2226. echo x - bin/what
  2227. cat >bin/what <<'!Funky!Stuff!'
  2228. cat $HOME/.query
  2229. echo -n 'save? (n or d to delete, e to edit) '
  2230. read response
  2231. case $response in
  2232.     n | no | d | delete)
  2233.     rm $HOME/.query && echo The query is removed. ;;
  2234.     "" | y | yes | s | save)
  2235.     exit ;;
  2236.     e | edit)
  2237.     exec vi $HOME/.query < /dev/tty
  2238.     exit ;;
  2239.     *)
  2240.     echo Bad response: "$response"
  2241.     exec $0 ;;
  2242. esac
  2243. !Funky!Stuff!
  2244. echo x - bin/whereis
  2245. cat >bin/whereis <<'!Funky!Stuff!'
  2246. N=$#
  2247. command=echo
  2248. case "$1" in
  2249.     -*)
  2250.     command=`expr "$1" : '-\(.*\)'`
  2251.     shift
  2252.     N=`expr $N - 1` ;;
  2253. esac
  2254. case $N in
  2255.     0)
  2256.     exec echo Usage: `basename $0` [ -command ] pattern file ...  ;;
  2257.     1)
  2258.     files=`fgrep -l "$1" *` ;;
  2259.     *)
  2260.     files=`fgrep -l "$@"` ;;
  2261. esac
  2262. case $files in
  2263.     "")
  2264.         echo $1 not found in any files.
  2265.         exit ;;
  2266. esac
  2267. exec $command $files
  2268. !Funky!Stuff!
  2269. echo x - bin/wide
  2270. cat >bin/wide <<'!Funky!Stuff!'
  2271. echo \"
  2272. !Funky!Stuff!
  2273. echo x - bin/xprint
  2274. cat >bin/xprint <<'!Funky!Stuff!'
  2275. case $# in
  2276.     1)
  2277.     eval $1 | eval pr -f -h \"$1\" | vpr -l ;;
  2278.     *)
  2279.     command='cat $file'
  2280.     for file
  2281.     do
  2282.         case $file in
  2283.         -*)
  2284.             command=`expr "$file" : '-\(.*\)'`
  2285.             case $command in
  2286.             *\$file*)
  2287.                 ;;
  2288.             *)
  2289.                 command="$command \$file" ;;
  2290.             esac ;;
  2291.         *)
  2292.             eval $command | eval pr -f -h \"$command\" | vpr -l ;;
  2293.         esac
  2294.     done
  2295. esac
  2296. !Funky!Stuff!
  2297. echo x - bin/archives
  2298. mkdir bin/archives
  2299. echo x - bin/archives/newsweed
  2300. cat >bin/archives/newsweed <<'!Funky!Stuff!'
  2301. #
  2302. cd
  2303. if ($#argv == 0) then
  2304.     if (-e .newsweed) then
  2305.     set WEEDGROUPS=`cat .newsweed`
  2306.     else
  2307.     set WEEDGROUPS=
  2308.     endif
  2309. else
  2310.     set WEEDGROUPS=$*
  2311. endif
  2312. if ($#WEEDGROUPS == 0) then
  2313.     onintr
  2314.     echo Searching for articles in all newsgroups
  2315.     readnews -l | \
  2316.     grep Subject | \
  2317.     sed -e 's/Subject: *//' -e 's/^[rR][eE]:*  *//' | \
  2318.     sort -u > /tmp/weed$$a
  2319.     if (-z /tmp/weed$$a) then
  2320.     echo No news.
  2321.     else
  2322.     cp /tmp/weed$$a /tmp/weed$$b
  2323.     echo Please remove article titles which you do not wish to read
  2324.     sleep 1
  2325.     onintr -
  2326.     vi /tmp/weed$$b
  2327.     onintr cleanup
  2328.     comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c
  2329.     echo Removing unwanted articles
  2330.     newsec -f /tmp/weed$$c
  2331.     endif
  2332. else
  2333.     foreach group ($WEEDGROUPS)
  2334.     echo Searching for articles in group\(s\):
  2335.     echo $group
  2336.     readnews -l -n $group | \
  2337.     grep Subject | \
  2338.     sed -e 's/Subject: *//' -e 's/^[rR]e:*  *//' | \
  2339.     sort -u > /tmp/weed$$a
  2340.     if (-z /tmp/weed$$a) then
  2341.         echo in newsgroups $group.
  2342.     else
  2343.         cp /tmp/weed$$a /tmp/weed$$b
  2344.         echo Please remove article titles which you do not wish to read
  2345.         sleep 1
  2346.         onintr -
  2347.         vi /tmp/weed$$b
  2348.         onintr cleanup
  2349.         comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c
  2350.         echo Removing unwanted articles
  2351.         newsec -f /tmp/weed$$c
  2352.     endif
  2353.     end
  2354. endif
  2355.  
  2356. cleanup:
  2357. rm /tmp/weed$$?
  2358. !Funky!Stuff!
  2359. echo x - bin/archives/pk_01
  2360. cat >bin/archives/pk_01 <<'!Funky!Stuff!'
  2361. : Roff, nroff, or eqn input text
  2362. for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'`
  2363. do
  2364.     echo "echo x - $file"
  2365.     echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  2366.     sed 's/^/x/' $file; echo "!Funky!Stuff!"
  2367. done
  2368. : Text files
  2369. for file in `file $* | sed -n -e '/commands text$/s/:[^:]*$//p' -e '/ascii text$/s/:[^:]*$//p'`
  2370. do
  2371.     echo "echo x - $file"
  2372.     echo "cat >$file <<'!Funky!Stuff!'"
  2373.     cat $file; echo "!Funky!Stuff!"
  2374. done
  2375. : Directories, recursively
  2376. for dir in `file $* | sed -n '/directory$/s/:.*//p'`
  2377. do
  2378.     echo "echo x - $dir"
  2379.     echo "mkdir $dir"
  2380.     file=`echo $dir/*`
  2381.     test "$file" != "$dir/*" && $0 $file
  2382. done
  2383. !Funky!Stuff!
  2384. echo x - bin/archives/pkf
  2385. cat >bin/archives/pkf <<'!Funky!Stuff!'
  2386.  
  2387. for dir
  2388. do
  2389.     echo "echo x - $dir"
  2390.     echo "mkdir $dir";
  2391.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  2392.     do
  2393.         echo "echo x - $file"
  2394.         echo "cat >$file <<'!Funky!Stuff!'"
  2395.         cat $file; echo "!Funky!Stuff!"
  2396.     done
  2397.     $0 `file $dir/* | sed -n '/directory$/s/:.*//p'`
  2398. done
  2399. !Funky!Stuff!
  2400. echo x - bin/archives/pkg
  2401. cat >bin/archives/pkg <<'!Funky!Stuff!'
  2402. for file
  2403. do
  2404.     echo "echo x - $file"
  2405.     echo "cat >$file <<'!Funky!Stuff!'"
  2406.     cat $file; echo "!Funky!Stuff!"
  2407. done
  2408. !Funky!Stuff!
  2409. echo x - bin/archives/pkn
  2410. cat >bin/archives/pkn <<'!Funky!Stuff!'
  2411.  
  2412. for dir
  2413. do
  2414.     echo "echo x - $dir"
  2415.     echo "mkdir $dir";
  2416.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  2417.     do
  2418.         echo "echo x - $file"
  2419.         echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  2420.         sed 's/^/x/' $file; echo "!Funky!Stuff!"
  2421.     done
  2422.     $0 `file $dir/* | sed -n '/directory$/s/:.*//p'`
  2423. done
  2424. !Funky!Stuff!
  2425. echo x - bin/archives/prod
  2426. cat >bin/archives/prod <<'!Funky!Stuff!'
  2427. #
  2428. set flags=()
  2429. set syslist=()
  2430. foreach arg ($argv)
  2431.     switch ($arg)
  2432.     case -s*:
  2433.         if (`expr $arg : '.*'` > 9) then
  2434.         rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.......\)'`
  2435.         else
  2436.         rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.*\)'`
  2437.         endif
  2438.         set syslist=($syslist $arg)
  2439.         breaksw
  2440.     case -*:
  2441.         set flags=($flags $arg)
  2442.         breaksw
  2443.     default:
  2444.         if (`expr $arg : '.*'` > 7) then
  2445.         rm -f /usr/spool/uucp/STST.`expr $arg : '\(.......\)'`
  2446.         else
  2447.         rm -f /usr/spool/uucp/STST.$arg
  2448.         endif
  2449.         set syslist=($syslist -s$arg)
  2450.         breaksw
  2451.     endsw
  2452. end
  2453. foreach sys ($syslist)
  2454.     /usr/lib/uucp/uucico -r1 $flags $sys
  2455. end
  2456. !Funky!Stuff!
  2457. echo x - bin/bourne_scripts
  2458. mkdir bin/bourne_scripts
  2459. echo x - bin/bourne_scripts/lookdoc
  2460. sed 's/^x//' >bin/bourne_scripts/lookdoc <<'!Funky!Stuff!'
  2461. xtrap exit 2
  2462. xcase $# in
  2463. x    0)
  2464. x    ul | more
  2465. x    exit ;;
  2466. xesac
  2467. xfor names
  2468. xdo
  2469. x    case $names in
  2470. x    -n)
  2471. x        default=n ;;
  2472. x    -t)
  2473. x        default=t ;;
  2474. x    -m*)
  2475. x        macros="$macros $names" ;;
  2476. x    *.n | *.nr)
  2477. x        nroff $macros $names | ul | more ;;
  2478. x    *.t | *.tbl)
  2479. x        soelim $names | tbl | nroff $macros - | ul | more ;;
  2480. x    *)
  2481. x        case $default in
  2482. x        n)
  2483. x            nroff $macros $names | ul | more ;;
  2484. x        t)
  2485. x            soelim $names | tbl | nroff $macros - | ul | more ;;
  2486. x        "")
  2487. x            ul $names | more ;;
  2488. x        esac
  2489. x    esac
  2490. xdone
  2491. !Funky!Stuff!
  2492. echo x - bin/bourne_scripts/CC
  2493. cat >bin/bourne_scripts/CC <<'!Funky!Stuff!'
  2494. outname=a.out
  2495. for argv
  2496. do
  2497.     case $argv in
  2498.     *.[cos])
  2499.         outname=`expr $argv : '\(.*\)\.'`
  2500.         break ;;
  2501.     esac
  2502. done
  2503. cc -o $outname $*
  2504. !Funky!Stuff!
  2505. echo x - bin/bourne_scripts/appt
  2506. cat >bin/bourne_scripts/appt <<'!Funky!Stuff!'
  2507. case $0 in
  2508.     appt)
  2509.     notetype=appointment
  2510.     notefile=$HOME/calendar ;;
  2511.     *)
  2512.     notetype=$0
  2513.     notefile=$HOME/.$0 ;;
  2514. esac
  2515.  
  2516. case $# in
  2517.     0)
  2518.     test -t 0 && echo Please enter your $notetype '(^D to end):'
  2519.     echo '' >> $notefile
  2520.     exec cat >> $notefile ;;
  2521. esac
  2522. case $1 in
  2523.     -)
  2524.     exec vi $notefile ;;
  2525.     -rm)
  2526.     cat /dev/null > $notefile
  2527.     exec echo The ${notetype}s are removed. ;;
  2528.     -what)
  2529.     exec cat $notefile ;;
  2530.     *)
  2531.     echo '' >> $notefile
  2532.     exec echo "$*" >> $notefile ;;
  2533. esac
  2534. !Funky!Stuff!
  2535. echo x - bin/bourne_scripts/beautify
  2536. cat >bin/bourne_scripts/beautify <<'!Funky!Stuff!'
  2537. for files
  2538. do
  2539.     echo $files:
  2540.     cb < $files > /tmp/cb$$
  2541.     cat /tmp/cb$$ > $files
  2542. done
  2543. rm /tmp/cb$$
  2544. !Funky!Stuff!
  2545. echo x - bin/bourne_scripts/format
  2546. cat >bin/bourne_scripts/format <<'!Funky!Stuff!'
  2547. case $# in
  2548.     0)
  2549.     echo "Usage: `basename $0` [-flags] <filename> [ <filename> ... ]"
  2550.     exit 1 ;;
  2551. esac
  2552. for names
  2553. do
  2554.     case $names in
  2555.     -*)
  2556.         flags="$flags $names" ;;
  2557.     *.t)
  2558.         outfile=`expr $names : '\(.*\)\.'`.d
  2559.         soelim $names | tbl | nroff $flags - > $outfile ;;
  2560.     *.tbl)
  2561.         outfile=`expr $names : '\(.*\)\.'`.doc
  2562.         soelim $names | tbl | nroff $flags - > $outfile ;;
  2563.     *.n)
  2564.         outfile=`expr $names : '\(.*\)\.'`.d
  2565.         nroff $flags $names > $outfile ;;
  2566.     *.nr)
  2567.         outfile=`expr $names : '\(.*\)\.'`.doc
  2568.         nroff $flags $names > $outfile ;;
  2569.     *)
  2570.         echo Don\'t know what to do with $names ;;
  2571.     esac
  2572. done
  2573. !Funky!Stuff!
  2574. echo x - bin/bourne_scripts/print
  2575. cat >bin/bourne_scripts/print <<'!Funky!Stuff!'
  2576. PATH=/avsd/ava/turk/bin:/usr/local/bin:/usr/bin
  2577. indent=0
  2578. for names
  2579. do
  2580.     case $names in
  2581.     -i)
  2582.         indent=1 ;;
  2583.     *)
  2584.         args="$args $names" ;;
  2585.     esac
  2586. done
  2587. case $indent in
  2588.     0)
  2589.     pr $args | lpr ;;
  2590.     *)
  2591.     pr $args | indent | lpr ;;
  2592. esac
  2593. !Funky!Stuff!
  2594. echo x - bin/bourne_scripts/repeat
  2595. cat >bin/bourne_scripts/repeat <<'!Funky!Stuff!'
  2596. case $1 in
  2597.     -[0-9]*)
  2598.     number=`expr $1 : '-\(.*\)'`
  2599.     shift
  2600.     while test $number -gt 0
  2601.     do
  2602.         eval $*
  2603.         number=`expr $number - 1`
  2604.     done
  2605.     exit ;;
  2606.     *)
  2607.     echo Executing forever: $* 1>&2
  2608.     number=0
  2609.     trap 'echo Executed $number times.; exit' 2
  2610.     while true
  2611.     do
  2612.         eval $*
  2613.         number=`expr $number + 1`
  2614.     done ;;
  2615. esac
  2616. !Funky!Stuff!
  2617. echo x - bin/bourne_scripts/restore
  2618. cat >bin/bourne_scripts/restore <<'!Funky!Stuff!'
  2619. case $# in
  2620.     2) ;;
  2621.     *)
  2622.     exec echo Usage: `basename $0` '<file>' '<version>' ;;
  2623. esac
  2624. : Truncate filename if necessary
  2625. if test `expr $1 : '.*'` -gt 11
  2626. then
  2627.     savename=`expr $1 : '\(...........\)'`
  2628. else
  2629.     savename=$1
  2630. fi
  2631. savename=${savename}_$2
  2632. cp $savename $1 && rm $savename && echo $1 restored from $savename
  2633. !Funky!Stuff!
  2634. echo x - bin/bourne_scripts/save
  2635. cat >bin/bourne_scripts/save <<'!Funky!Stuff!'
  2636. for file
  2637. do
  2638.     if test `expr $file : '.*'` -gt 11
  2639.     then
  2640.     savename=`expr $file : '\(...........\)'`
  2641.     else
  2642.     savename=$file
  2643.     fi
  2644.     for copy in ${savename}_??
  2645.     do
  2646.     latest=$copy
  2647.     done
  2648.     if test $latest = "${savename}_??"
  2649.     then
  2650.     latest=${savename}_01
  2651.     else
  2652.     latest=`expr $latest : '.*_\([0123456789]*\)$' + 1`
  2653.     case $latest in
  2654.         ?)
  2655.         latest=0$latest
  2656.         ;;
  2657.     esac
  2658.     latest=${savename}_$latest
  2659.     fi
  2660.     cp $file $latest && echo $file saved as $latest
  2661. done
  2662. !Funky!Stuff!
  2663. echo x - bin/csh_scripts
  2664. mkdir bin/csh_scripts
  2665. echo x - bin/csh_scripts/newsweed
  2666. cat >bin/csh_scripts/newsweed <<'!Funky!Stuff!'
  2667. #
  2668. set TEMP=/tmp/weed$$
  2669. set NEWSRC=~/.newsrc
  2670. set AWKFILE=/usr/ken/cmd/lib/newsweed.awk
  2671. onintr
  2672. echo Searching for articles in all newsgroups
  2673. readnews -l $* | sort -o ${TEMP}a
  2674. if (-z ${TEMP}a) then
  2675.     echo No news.
  2676. else
  2677.     cp ${TEMP}a ${TEMP}b
  2678.     echo Please remove article titles which you do not wish to read
  2679.     sleep 1
  2680.     onintr -
  2681.     vi ${TEMP}b
  2682.     onintr cleanup
  2683.     if ( { cmp -s ${TEMP}a ${TEMP}b } ) then
  2684.     echo No articles deleted.
  2685.     else
  2686.     comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c
  2687.     echo Removing unwanted articles
  2688.     cp $NEWSRC $NEWSRC.old
  2689.     awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d
  2690.     cp ${TEMP}d $NEWSRC
  2691.     endif
  2692. endif
  2693. cleanup:
  2694. rm ${TEMP}?
  2695. !Funky!Stuff!
  2696. echo x - bin/csh_scripts/pathname
  2697. cat >bin/csh_scripts/pathname <<'!Funky!Stuff!'
  2698. #
  2699. foreach cmddir ($path)
  2700.     if ( -e $cmddir/$1 ) echo "    $cmddir/$1"
  2701. end
  2702. !Funky!Stuff!
  2703. echo x - bin/local
  2704. mkdir bin/local
  2705. echo x - bin/local/format
  2706. cat >bin/local/format <<'!Funky!Stuff!'
  2707. #
  2708. if ($#argv == 0) then
  2709.     set progname=$0
  2710.     set progname=$progname:t
  2711.     echo 'Usage:' $progname '[-v] [-n] [-print] [-troffflags] <filename> [ <filename> ... ]'
  2712.     exit (1)
  2713. endif
  2714. set flags
  2715. set formatter="vtroff -t"
  2716. set eqnsetter=eqn
  2717. set docsuf=v
  2718. set longdocsuf=vpr
  2719. set more=0
  2720. foreach name ($argv)
  2721.     if ($more > 0) then
  2722.     set flags="$flags $name"
  2723.     @ more--
  2724.     continue
  2725.     endif
  2726.     switch ($name)
  2727.     case -*:
  2728.         switch ($name)
  2729.         case -print:
  2730.             set print
  2731.             continue
  2732.         case -v:
  2733.             set formatter="vtroff -t"
  2734.             set eqnsetter=eqn
  2735.             set docsuf=v
  2736.             set longdocsuf=vpr
  2737.             continue
  2738.         case -n:
  2739.             set formatter=nroff
  2740.             set eqnsetter=neqn
  2741.             set docsuf=d
  2742.             set longdocsuf=doc
  2743.             continue
  2744.         case -[F123]:
  2745.             set more=1
  2746.         default:
  2747.             set flags="$flags $name"
  2748.         endsw
  2749.         continue
  2750.     case *.et:
  2751.         set outfile=$name:r.$docsuf
  2752.         eval soelim $name | tbl | $eqnsetter | $formatter $flags > $outfile
  2753.         breaksw
  2754.     case *.t:
  2755.         set outfile=$name:r.$docsuf
  2756.         eval soelim $name | tbl | $formatter $flags > $outfile
  2757.         breaksw
  2758.     case *.tbl:
  2759.         set outfile=$name:r.$longdocsuf
  2760.         eval soelim $name | tbl | $formatter $flags > $outfile
  2761.         breaksw
  2762.     case *.e:
  2763.         set outfile=$name:r.$docsuf
  2764.         eval $eqnsetter $name | $formatter $flags > $outfile
  2765.         breaksw
  2766.     case *.eqn:
  2767.         set outfile=$name:r.$longdocsuf
  2768.         eval $eqnsetter $name | $formatter $flags > $outfile
  2769.         breaksw
  2770.     case *.n:
  2771.         set outfile=$name:r.$docsuf
  2772.         eval $formatter $flags $name > $outfile
  2773.         breaksw
  2774.     case *.nr:
  2775.         set outfile=$name:r.$longdocsuf
  2776.         eval $formatter $flags $name > $outfile
  2777.         breaksw
  2778.     default:
  2779.         echo Don\'t know what to do with $name
  2780.         continue
  2781.     endsw
  2782.     if ($?print) then
  2783.     if ("$formatter" == nroff) then
  2784.         vpr $outfile
  2785.     else
  2786.         vpr -t $outfile
  2787.     endif
  2788.     endif
  2789. end
  2790. !Funky!Stuff!
  2791. echo x - bin/local/lntree
  2792. cat >bin/local/lntree <<'!Funky!Stuff!'
  2793. PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin
  2794. if test $1 = -v
  2795. then
  2796.     verbose=1
  2797.     shift
  2798. else
  2799.     verbose=0
  2800. fi
  2801. case $2 in
  2802.     /*)
  2803.     target=$2 ;;
  2804.     *)
  2805.     target=`pwd`/$2 ;;
  2806. esac
  2807. if test -f $2
  2808. then
  2809.     echo Error: $2 is not a directory
  2810.     exit 1
  2811. fi
  2812. cd $1
  2813. source=`pwd`
  2814. if test `expr $target : $source/` != 0
  2815. then
  2816.     echo Error: $2 may be a subdirectory of $1
  2817.     echo Try using the full path name of $2 \(no ..\'s\)
  2818.     exit 1
  2819. fi
  2820. if test $verbose = 1
  2821. then
  2822.     set -x
  2823. fi
  2824. files=`type -f`
  2825. case $files in
  2826.     "") ;;
  2827.     *)
  2828.     ln $files $target ;;
  2829. esac
  2830. for directory in `find '' -type d -a -print`
  2831. do
  2832.     mkdir $target$directory
  2833.     cd $source$directory
  2834.     files=`type -f`
  2835.     case $files in
  2836.     "") ;;
  2837.     *)
  2838.         ln $files $target$directory ;;
  2839.     esac
  2840. done
  2841. !Funky!Stuff!
  2842. echo x - bin/local/lookdoc
  2843. cat >bin/local/lookdoc <<'!Funky!Stuff!'
  2844. #
  2845. if ($#argv == 0) then
  2846.     more
  2847.     exit
  2848. endif
  2849. set macros pipespec args
  2850. foreach name ($argv)
  2851.     switch ($name)
  2852.     case -n:
  2853.         set pipespec=n
  2854.         breaksw
  2855.     case -t:
  2856.         set pipespec=t
  2857.         breaksw
  2858.     case -m*:
  2859.         set macros="$macros $name"
  2860.         breaksw
  2861.     case *.n:
  2862.     case *.nr:
  2863.         if ($pipespec != t) set pipespec=n
  2864.         set args="$args $name"
  2865.         breaksw
  2866.     case *.t:
  2867.     case *.tbl:
  2868.         set pipespec=t
  2869.         set args="$args $name"
  2870.         breaksw
  2871.     default:
  2872.         set args="$args $name"
  2873.     endsw
  2874. end
  2875.  
  2876. switch ($pipespec)
  2877.     case n:
  2878.     nroff $macros $args | more
  2879.     breaksw
  2880.     case t:
  2881.     soelim $args | tbl | nroff $macros - | col | more
  2882.     breaksw
  2883.     default:
  2884.     more $name
  2885.     breaksw
  2886. endsw
  2887. !Funky!Stuff!
  2888. echo x - bin/local/newsweed
  2889. cat >bin/local/newsweed <<'!Funky!Stuff!'
  2890. TEMP=/tmp/weed$$
  2891. NEWSRC=$HOME/.newsrc
  2892. AWKFILE=/usr/local/lib/newsweed.awk
  2893. trap 'rm ${TEMP}?; exit' 0 2
  2894. echo Making list of article titles
  2895. readnews -l $* | sort -o ${TEMP}a
  2896. if test -s ${TEMP}a
  2897. then
  2898.     cp ${TEMP}a ${TEMP}b
  2899.     echo Please remove article titles which you do not wish to read
  2900.     sleep 1
  2901.     reset    # So that vi's CRLF doesn't get trashed by another vi
  2902.     ${EDITOR-vi} ${TEMP}b
  2903.     if cmp -s ${TEMP}a ${TEMP}b
  2904.     then
  2905.     echo No articles deleted.
  2906.     else
  2907.     comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c
  2908.     echo Removing unwanted articles
  2909.     cp $NEWSRC $NEWSRC.old
  2910.     awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d
  2911.     cp ${TEMP}d $NEWSRC
  2912.     fi
  2913. else
  2914.     echo No news.
  2915. fi
  2916. !Funky!Stuff!
  2917. echo x - bin/local/nmail
  2918. cat >bin/local/nmail <<'!Funky!Stuff!'
  2919. #/bin/csh
  2920. set found = 0
  2921. set arg = 1
  2922. while($arg <= $#argv)
  2923.     if(`echo $argv[$arg] | grep \!` != "") then
  2924.         set tuple = `echo $argv[$arg] | sed s/\\!/\ /`
  2925.         set upath = `uupath $tuple[1]`
  2926.         set found = $status
  2927.         set argv[$arg] = "$upath\!$tuple[2]"
  2928.     else
  2929.         set found = 0
  2930.     endif
  2931.     if($found != 0) then
  2932.         set argv[$arg]
  2933.     endif
  2934.     @ arg = $arg + 1
  2935. end
  2936. echo "mail $argv"
  2937. mail $argv
  2938.  
  2939. !Funky!Stuff!
  2940. echo x - bin/local/peopledata
  2941. cat >bin/local/peopledata <<'!Funky!Stuff!'
  2942. peoplefile=$HOME/.peopledata
  2943.  
  2944. echo ' '
  2945.  
  2946. case $# in
  2947.     0)
  2948.     ed - $peoplefile << EOF
  2949. g/./s/$/\\
  2950. /
  2951. g/    /s//\\
  2952. /g
  2953. 1,\$p
  2954. q
  2955. EOF
  2956.     exit ;;
  2957. esac
  2958.  
  2959. case $1 in
  2960.     -)
  2961.     chmod 600 $peoplefile
  2962.     vi $peoplefile
  2963.     chmod 400 $peoplefile
  2964.     exit ;;
  2965. esac
  2966. trap "rm /tmp/data$$; exit" 0 2
  2967. for name
  2968. do
  2969.     grep -y "$name" $peoplefile >> /tmp/data$$
  2970. done
  2971. ed - /tmp/data$$ << EOF
  2972. g/./s/$/\\
  2973. /
  2974. g/    /s//\\
  2975. /g
  2976. 1,\$p
  2977. q
  2978. EOF
  2979. !Funky!Stuff!
  2980. echo x - bin/local/phone
  2981. cat >bin/local/phone <<'!Funky!Stuff!'
  2982. peoplefile=$HOME/.peopledata
  2983.  
  2984. case $# in
  2985.     0)
  2986.     ed - $peoplefile << EOF
  2987.     v/-/d
  2988.     g/./s/\([^    ]*\)[^-]*    \(.*-.*\)/\1    \2/
  2989.     1,\$p
  2990. EOF
  2991.     exit ;;
  2992. esac
  2993.  
  2994. case $1 in
  2995.     -)
  2996.     chmod 600 $peoplefile
  2997.     vi $peoplefile
  2998.     chmod 400 $peoplefile
  2999.     exit ;;
  3000. esac
  3001.  
  3002. trap "rm /tmp/data$$; exit" 0 2
  3003. for name
  3004. do
  3005.     grep -y "$name" $peoplefile >> /tmp/data$$
  3006. done
  3007. ed - /tmp/data$$ << EOF
  3008. g/./s/\([^    ]*\)[^-]*    \(.*-.*\)/\1    \2/
  3009. 1,\$p
  3010. q
  3011. EOF
  3012. !Funky!Stuff!
  3013. echo x - bin/local/pk
  3014. cat >bin/local/pk <<'!Funky!Stuff!'
  3015. for dir
  3016. do echo "mkdir $dir";
  3017.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  3018.     do    echo "echo x - $file"
  3019.         echo "cat >$file <<'#EOF#'"
  3020.         cat $file; echo "#EOF#"
  3021.     done
  3022.     pk `file $dir/* | sed -n '/directory$/s/:.*//p'`
  3023. done
  3024. !Funky!Stuff!
  3025. echo x - bin/local/save
  3026. cat >bin/local/save <<'!Funky!Stuff!'
  3027. #
  3028. if ("$1" =~ -*) then
  3029.     set suffix=`expr $1 : '-\(.*\)'`
  3030.     shift
  3031.     foreach file ($argv)
  3032.     if (`expr $file:t : '.*'` >= 11) then
  3033.         set savename=`expr $file : '\(.*\)'$file:t`
  3034.         set savename=$savename`expr $file:t : '\(...........\)'`
  3035.     else
  3036.         set savename=$file
  3037.     endif
  3038.     cp $file ${savename}_$suffix && \
  3039.         echo $file saved as ${savename}_$suffix
  3040.     end
  3041.     exit
  3042. endif
  3043. foreach file ($argv)
  3044.     if (`expr $file:t : '.*'` >= 11) then
  3045.     set savename=`expr $file : '\(.*\)'$file:t`
  3046.     set savename=$savename`expr $file:t : '\(...........\)'`
  3047.     else
  3048.     set savename=$file
  3049.     endif
  3050.  
  3051.     set nonomatch
  3052.     set latest=(${savename}_[0-9][0-9])
  3053.     if ("$latest" == "${savename}_[0-9][0-9]") then
  3054.     set latest=${savename}_01
  3055.     else
  3056.     set latest=$latest[$#latest]
  3057.     set latest=`expr $latest : '.*_\([0123456789]*\)$' + 1`
  3058.     if ($latest < 10) set latest=0$latest
  3059.     set latest=${savename}_$latest
  3060.     endif
  3061.     cp $file $latest && echo $file saved as $latest
  3062. end
  3063. !Funky!Stuff!
  3064. echo x - bin/local/shar
  3065. cat >bin/local/shar <<'!Funky!Stuff!'
  3066. : Roff, nroff, or eqn input text
  3067. for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'`
  3068. do
  3069.     echo "echo x - $file"
  3070.     echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  3071.     sed 's/^/x/' $file; echo "!Funky!Stuff!"
  3072. done
  3073. : Text files
  3074. for file in `file $* | sed -n -e '/eqn input text$/d' -e '/text$/s/:[^:]*$//p'`
  3075. do
  3076.     echo "echo x - $file"
  3077.     echo "cat >$file <<'!Funky!Stuff!'"
  3078.     cat $file; echo "!Funky!Stuff!"
  3079. done
  3080. : Directories, recursively
  3081. for dir in `file $* | sed -n '/directory$/s/:.*//p'`
  3082. do
  3083.     echo "echo x - $dir"
  3084.     echo "mkdir $dir"
  3085.     file=`echo $dir/*`
  3086.     test "$file" != "$dir/*" && $0 $file
  3087. done
  3088. !Funky!Stuff!
  3089. echo x - bin/local/uuhosts
  3090. cat >bin/local/uuhosts <<'!Funky!Stuff!'
  3091. #!/bin/sh
  3092. # '@(#) uuhosts.sh 1.22 84/08/07'
  3093.  
  3094. # PATH will have to be adjusted for non-BSD systems.
  3095. PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin
  3096. LIB=/usr/lib
  3097.  
  3098. # Routing information produced by pathalias.
  3099. paths=$LIB/nmail.paths
  3100.  
  3101. # The directory $NEWSMAP should contain the USENET news map information
  3102. # from newsgroup net.news.map that is posted about once a month from
  3103. # cbosgd!map, extracted by a line like this in $LIB/news/sys:
  3104. #
  3105. #    newsmap:net.news.map:B:/usr/local/uuhosts -x
  3106. #
  3107. # Locally-known information should go in $LIB/news/net.news.map/Local.
  3108. # The directory $MAILMAP is extracted by the same command from the
  3109. # UUCP mail information posted to the same newsgroup.
  3110. NEWSMAP=$LIB/news/net.news.map
  3111. MAILMAP=$LIB/news/net.mail.map
  3112. cd $NEWSMAP
  3113.  
  3114. case $1 in
  3115.     -x)
  3116.         # extract a new map piece into the map directory
  3117.         temphead=/tmp/maphead.$$
  3118.         temptext=/tmp/maptext.$$
  3119.         awk '
  3120. BEGIN    {
  3121.     temphead = "'$temphead'";
  3122.     isnewsmap = 0; ismailmap = 0;
  3123.     shead = 0; stext = 1; snews = 2; smail = 3; scat = 4; scatting = 5;
  3124.     state = shead;
  3125.     print "Reply-To: news" >> temphead;
  3126. }
  3127. state == shead && /^From: /    {
  3128.     print "Original-" $0 >> temphead;
  3129. }
  3130. state == shead && /^Subject: /    {
  3131.     if ($2 != "Re:")
  3132.     for (x = 2; x <= NF; x++) {
  3133.         if ($x == "UUCPmap" || $x == "uucpmap" || $x == "UUCPMAP") {
  3134.             ismailmap = 1;
  3135.             break;
  3136.         }
  3137.         if ($x == "map" || $x == "Map" || $x == "MAP") {
  3138.             if (x <= 2)
  3139.                 continue;
  3140.             x--;
  3141.             if ($x == "USENET") {
  3142.                 isnewsmap = 1;
  3143.                 break;
  3144.             }
  3145.             if ($x == "UUCP") {
  3146.                 ismailmap = 1;
  3147.                 break;
  3148.             }
  3149.             x++;
  3150.         }
  3151.     }
  3152.     if (!isnewsmap && !ismailmap) {
  3153.         print "Subject:  not a map update" >> temphead;
  3154.         print "Original-" $0 >> temphead;
  3155.     } else
  3156.         print $0 >> temphead;
  3157. }
  3158. state == shead && /^$/    {
  3159.     if (isnewsmap != 0)
  3160.         state = snews;
  3161.     else if (ismailmap != 0) {
  3162.         state = scat;
  3163.     } else
  3164.         state = stext;
  3165.     next;
  3166. }
  3167. state == scat    {
  3168.     if ($1 != "cat")
  3169.         state = scatting;
  3170.     else
  3171.         state = smail;
  3172. }
  3173. state == scatting {
  3174.     if ($1 == ":")
  3175.         state = smail;
  3176.     else
  3177.         print;
  3178. }
  3179. state == smail    {
  3180.     print | "uuhosts -u";
  3181. }
  3182. state == snews    {
  3183.     print | "/bin/sh";
  3184. }
  3185. state == stext    {
  3186.     print;
  3187. }
  3188. ' > $temptext 2>&1
  3189.         cat $temphead $temptext | /bin/mail news
  3190.         rm -f $temphead $temptext
  3191.         exit 0
  3192.     ;;
  3193.  
  3194.     -u)
  3195.         # extract a UUCP map piece
  3196.         cd $MAILMAP
  3197.         /bin/sh
  3198.         for f in *map*.a *map*.ar
  3199.         do
  3200.             ar xv $f
  3201.             rm $f
  3202.         done
  3203.     ;;
  3204.  
  3205.     -g)
  3206.         # by geographical region
  3207.         shift
  3208.         if test $# -eq 0
  3209.         then
  3210.             exec ls
  3211.             exit 1
  3212.         fi
  3213.         exec cat $*
  3214.         exit 1
  3215.     ;;
  3216.  
  3217.     -k)
  3218.         # by keyword
  3219.         shift
  3220.         exec awk '
  3221. BEGIN        { inside = 1; outside = 0; state = outside; }
  3222. /^Name:/    { state = inside; count = 0; useit = 0; }
  3223. state == inside    { block[count++] = $0; }
  3224. /'"$*"'/    { useit = 1; }
  3225. /^$/ && state == inside    {
  3226.     if (useit == 1) {
  3227.         for (i = 0; i < count; i++) {
  3228.             print block[i];
  3229.         }
  3230.     }
  3231.     state = outside;
  3232. }
  3233. ' *
  3234.         exit 1
  3235.     ;;
  3236.  
  3237.     -*)
  3238.         # unknown option
  3239.     ;;
  3240.  
  3241.     "")
  3242.         # no arguments
  3243.     ;;
  3244.  
  3245.     *)
  3246.         # by site name
  3247.         for arg in $*
  3248.         do
  3249.             echo 'UUCP mail path:'
  3250.             grep '^'${arg} $paths
  3251.             echo '
  3252. UUCP mail host information:'
  3253.             cat $MAILMAP/${arg}* | tr % '\012'
  3254.             echo '
  3255. USENET news host information:'
  3256.             sed -n -e "/^Name:[     ]*${arg}/,/^$/p" *
  3257.         done
  3258.         exit 0
  3259.     ;;
  3260. esac
  3261.  
  3262. echo 'Usage:    'uuhosts' hostname ...
  3263. for information about a particular UUCP or USENET host or hosts, or
  3264.  
  3265.     'uuhosts' -g geographical-region
  3266. for information about USENET news sites in a geographical region, or
  3267.  
  3268.     'uuhosts' -g
  3269. for a list of known USENET geographical-regions.
  3270. '
  3271. exit 1
  3272. !Funky!Stuff!
  3273.  
  3274. ::::::::::::::
  3275. shells/4
  3276. ::::::::::::::
  3277. Date: Fri, 14 Sep 84 15:06:07 pdt
  3278. From: hplabs!sdcrdcf!sdcsvax!celerity!barto (David Barto)
  3279. To: sdcsvax!sdcrdcf!hplabs!resonex!nancy
  3280. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  3281.  
  3282. Hi Nancy,
  3283.     I too am a 'new' system admin, and belive me, it won't take
  3284.     you too long to get quite a bag of tricks put together.
  3285.  
  3286.     Most of mine relate to source programs put together in
  3287.     shell scripts to keep track of things.
  3288.  
  3289.     I have 1 for news (at the end of the article) which keeps
  3290.     the active list up to date.
  3291.  
  3292.     Another nice program is one I call '#'.  It is owned by root
  3293.     and setuid/setgid to root/daemon.  I use it to 'become' root
  3294.     while doing 1 command
  3295.             # mv file1 file2
  3296.     which requires root permission.  It checks to see the normal
  3297.     userid is 'me' and then allows the command.  I will send it
  3298.     along if you want it.
  3299.  
  3300.     I have shell scripts for doing things such as 'rootedit'
  3301.     a file.  This is an alias for "alias re  '# vi -v \!*'"
  3302.  
  3303.     I too would love to see the things you get back from the
  3304.     net.  As well I have a sendmail config setup for making
  3305.     your configuration a breeze.  If you want it I can send
  3306.     it under seperate cover.
  3307.  
  3308.  
  3309.     barto (david barto)    Tele : (619) 271 9940
  3310.     uucp : {decvax || ucbvax || ihnp4}!sdcsvax!celerity!barto
  3311.     uucp : akgua!celerity!barto
  3312.     arpa : sdcsvax!celerity!barto@NOSC
  3313.  
  3314.  
  3315. : This is a shar archive.  Extract with sh, not csh.
  3316. echo x - Mkactive
  3317. cat > Mkactive << '!Funky!Stuff!'
  3318. #!/bin/sh
  3319. # see Update.active for this usage
  3320. #
  3321. sed -e '1,/---/d'\
  3322.     -e '1,/---/d'\
  3323.     -e 's/^[    ]//'\
  3324.     -e 's/    \(.*\)//'\
  3325.     active.current | sort | sed -e '1,/Newsgroup/d' > current
  3326. sed -e 's/ \(.*\)//' /usr/new/lib/news/active | sort > active
  3327. diff active current > /tmp/active.diff
  3328. echo "# active newsgroups not in local active file:"
  3329. fgrep ">" /tmp/active.diff
  3330. echo "# defunct newsgroups still in active file (also local groups):"
  3331. fgrep "<" /tmp/active.diff
  3332. /bin/rm current active /tmp/active.diff
  3333. !Funky!Stuff!
  3334. echo x - Mkdead
  3335. cat > Mkdead << '!Funky!Stuff!'
  3336. #!/bin/sh
  3337. # see Update.active for usage
  3338. # change all groups that we have (but shouldn't) to be removed,
  3339. # and change all groups that we dont have (but sould) to be a comment
  3340. sed    -e '/general/d'\
  3341.     -e '/control/d' \
  3342.     -e '/junk/d' \
  3343.     -e 's/</rmgroup/' \
  3344.     -e 's/>/#/'
  3345. !Funky!Stuff!
  3346. echo x - rmgroup
  3347. cat > rmgroup << '!Funky!Stuff!'
  3348. #! /bin/sh
  3349. # from : sdcsvax!sdcrdcf!hplabs!hao!seismo!rlgvax!cvl!umcp-cs!eneevax!chris
  3350. #
  3351. # @(#)rmgroup.sh    (U of Maryland) FLB 28-Jun-1983
  3352. #            Bug fixes 5 June 1984 Chris Torek
  3353. #
  3354. # Delete a newsgroup
  3355.  
  3356. lib=/usr/new/lib/news
  3357. spool=/usr/spool/news
  3358.  
  3359. group=$*
  3360.  
  3361. for group
  3362. do
  3363.     qgrp="`echo $group | sed 's/\./\\\./g'`"
  3364.     if
  3365.         grep -s "^$qgrp [0-9][0-9][0-9][0-9][0-9]$" $lib/active
  3366.     then
  3367.         ed - $lib/active << xxxFOOxxx
  3368. /^$qgrp [0-9][0-9][0-9][0-9][0-9]$/d
  3369. w
  3370. q
  3371. xxxFOOxxx
  3372.     else
  3373.         echo "$0: $group: no such active line" 2>&1
  3374.     fi
  3375.  
  3376.     dir=$spool/"`echo $group | sed 's/\./\//g'`"
  3377.     if
  3378.         [ -d "$dir" ]
  3379.     then
  3380.         /bin/rm -fr "$dir"
  3381.     else
  3382.         echo "$0: $dir: no spool directory" 2>&1
  3383.     fi
  3384. done
  3385. exit 0
  3386. !Funky!Stuff!
  3387.  
  3388. ::::::::::::::
  3389. shells/5
  3390. ::::::::::::::
  3391. Date: Thu, 20 Sep 84 01:20:29 pdt
  3392. From: turtlevax!ken (Ken Turkowski)
  3393. To: resonex!nancy
  3394. Subject: Handy new uucp utility: uuque
  3395.  
  3396. cat << EOF
  3397. I just completed a new useful uucp utility which lets you know what kind
  3398. of uucp work is in progress.  While uusnap just tells you the number of
  3399. files to be processed, uuque tells you exactly what kind of work is to
  3400. be performed.  I've only tried it on three kinds of work, namely mail,
  3401. news, and standard uucp transfers.  Give it a try, and see if it breaks
  3402. on any new types of uucp work.
  3403.                 Ken
  3404. P.S. This really should be a C program.
  3405. EOF
  3406. echo x - uuque
  3407. cat >uuque <<'!Funky!Stuff!'
  3408. #! /bin/sh
  3409. # uusnap
  3410. cd /usr/spool/uucp
  3411. LUUNAME=`uuname -l`
  3412.  
  3413. # Check for outgoing work
  3414. for cmdfile in C./*
  3415. do
  3416.     test -f $cmdfile || continue
  3417.     othersys=`expr $cmdfile : 'C./C.\(.*\).....'`
  3418.     cmd=
  3419.     dfile=
  3420.     xfile=
  3421.     ufile=
  3422.     cat $cmdfile | {
  3423.     while read cmd arg1 arg2 arg3 extra
  3424.     do
  3425.         case $cmd in
  3426.         S) ;;
  3427.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra
  3428.             exit ;;
  3429.         esac
  3430.         case $arg1 in
  3431.         D.${LUUNAME}X????)    # Remote execute file
  3432.             xfile=$arg1
  3433.             ;;
  3434.         D.${LUUNAME}?????)    # Data file ref'd by the execute file
  3435.             dfile=$arg1
  3436.             ;;
  3437.         *)            # Just a uucp
  3438.             dfile=$arg1
  3439.             ufile=$arg2
  3440.             from=$arg3
  3441.             ;;
  3442.         esac
  3443.     done
  3444.     case $xfile in
  3445.         "")            # uucp transfer
  3446.         echo `wc -c < $dfile`\     uucp $dfile $othersys!$ufile \($from\)
  3447.         ;;
  3448.         *)            # complex transfer
  3449.         cat D.${LUUNAME}X/$xfile | {
  3450.             while read xcmd arg1 arg2 extra
  3451.             do
  3452.             case $xcmd in
  3453.                 U)
  3454.                 from=$arg2!$arg1
  3455.                 ;;
  3456.                 F)
  3457.                 ;;
  3458.                 I)
  3459.                 ;;
  3460.                 C)
  3461.                 echo `wc -c < D.${LUUNAME}/$dfile`\     $arg1 $othersys!$arg2 \($from\)
  3462.                 ;;
  3463.                 *)
  3464.                 echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2
  3465.                 exit
  3466.                 ;;
  3467.             esac
  3468.             done
  3469.         }
  3470.         ;;
  3471.     esac
  3472.     }
  3473. done
  3474.  
  3475. # Check for incoming work
  3476. for cmdfile in X./*
  3477. do
  3478.     test -f $cmdfile || continue
  3479.     othersys=`expr $cmdfile : 'X./X.\(.*\).....'`
  3480.     cat $cmdfile | {
  3481.     while read cmd arg1 arg2 extra
  3482.     do
  3483.         case $cmd in
  3484.         U)
  3485.             from=$arg2!$arg1
  3486.             ;;
  3487.         Z)
  3488.             ;;
  3489.         F)
  3490.             if test -f D./$arg1
  3491.             then
  3492.             dfile=D./$arg1
  3493.             elif test -f D./$arg2
  3494.             then
  3495.             dfile=D./$arg2
  3496.             else
  3497.             continue 2
  3498.             fi
  3499.             ;;
  3500.         C)
  3501.             xcmd=$arg1
  3502.             ;;
  3503.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra
  3504.             exit ;;
  3505.         esac
  3506.     done
  3507.     echo `wc -c < $dfile`\     $xcmd $dfile \($from\)
  3508.     }
  3509. done
  3510. !Funky!Stuff!
  3511.  
  3512. ::::::::::::::
  3513. shells/6
  3514. ::::::::::::::
  3515. Date: Sat, 22 Sep 84 01:22:39 pdt
  3516. From: turtlevax!ken (Ken Turkowski)
  3517. To: resonex!nancy
  3518. Subject: Re:  uuque 
  3519.  
  3520. I've updated uuque to the point where it should probably instead be called
  3521. uusnoop.  Of course, it's not that interesting unless there are others on
  3522. your system that use uucp and net mail.
  3523.  
  3524.             Ken
  3525.  
  3526. echo x - uuque
  3527. cat >uuque <<'!Funky!Stuff!'
  3528. #! /bin/sh
  3529. # The user must have access to the /usr/spool/uucp/* directories and files.
  3530. # This can be easily done by making certain users members of the daemon
  3531. # and/or uucp groups, or by becoming super-user.
  3532. # uusnap
  3533. cd /usr/spool/uucp
  3534. LUUNAME=`uuname -l`
  3535.  
  3536. # Check for outgoing work
  3537. for cmdfile in C./*
  3538. do
  3539.     test -f $cmdfile || continue
  3540.     othersys=`expr $cmdfile : 'C./C.\(.*\).....'`
  3541.     cmd=
  3542.     dfile=
  3543.     xfile=
  3544.     ufile=
  3545.     cat $cmdfile | {
  3546.     while read cmd arg1 arg2 arg3 extra
  3547.     do
  3548.         case $cmd in
  3549.         S)                # uucp send
  3550.             case $arg1 in
  3551.             D.${LUUNAME}X????)    # Remote execute file
  3552.                 xfile=$arg1
  3553.                 ;;
  3554.             D.${LUUNAME}?????)    # Data file ref'd by xfile
  3555.                 dfile=D.${LUUNAME}/$arg1
  3556.                 ;;
  3557.             *)        # Just a uucp -- no intertpretation
  3558.                 echo `wc -c < $arg1`\     uucp $arg1 $othersys!$arg2 \($arg3\)
  3559.                 ;;
  3560.             esac
  3561.             ;;
  3562.         R)        # uucp receive
  3563.             echo '    ' uucp $othersys!$arg1 $arg2 \($arg3\)
  3564.             ;;
  3565.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra
  3566.             continue ;;
  3567.         esac
  3568.     done
  3569.     case $xfile in
  3570.         "")            # uucp transfer
  3571.         continue
  3572.         ;;
  3573.     esac
  3574.     cat D.${LUUNAME}X/$xfile | {    # complex transfer -- interpret xfile
  3575.         while read xcmd arg1 arg2 extra
  3576.         do
  3577.         case $xcmd in
  3578.             U)
  3579.             from=$arg2!$arg1
  3580.             ;;
  3581.             F)
  3582.             ;;
  3583.             I)
  3584.             ;;
  3585.             Z)
  3586.             ;;
  3587.             C)
  3588.             case $arg1 in
  3589.                 rmail)
  3590.                 from=`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
  3591.                 echo `wc -c < $dfile`\     $arg1 $othersys!$arg2 \($from\)
  3592.                 echo -n '     '
  3593.                 grep '^Subject:' $dfile || echo ''
  3594.                 ;;
  3595.                 rnews)
  3596.                 echo `wc -c < $dfile`\     $arg1 $othersys  \($from\)
  3597.                 echo -n '     '
  3598.                 grep '^Newsgroups:' $dfile
  3599.                 echo -n '     '
  3600.                 grep '^Subject:' $dfile
  3601.                 ;;
  3602.                 *)
  3603.                 echo `wc -c < $dfile`\     $arg1 $arg2 $extra [$othersys $dfile] \($from\)
  3604.                 ;;
  3605.             esac
  3606.             ;;
  3607.             *)
  3608.             echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2
  3609.             exit
  3610.             ;;
  3611.         esac
  3612.         done
  3613.     }
  3614.     }
  3615. done
  3616.  
  3617. # Check for incoming work
  3618. for cmdfile in X./*
  3619. do
  3620.     test -f $cmdfile || continue
  3621.     othersys=`expr $cmdfile : 'X./X.\(.*\).....'`
  3622.     comment=
  3623.     cat $cmdfile | {
  3624.     while read cmd arg1 arg2 extra
  3625.     do
  3626.         case $cmd in
  3627.         U)
  3628.             from=$arg2!$arg1
  3629.             ;;
  3630.         Z)
  3631.             ;;
  3632.         I)
  3633.             ;;
  3634.         F)
  3635.             if test -f D./$arg1
  3636.             then
  3637.             dfile=D./$arg1
  3638.             elif test -f XTMP/$arg2
  3639.             then
  3640.             dfile=XTMP/$arg2
  3641.             comment="(EXECUTING)"
  3642.             else
  3643.             continue 2
  3644.             fi
  3645.             ;;
  3646.         C)
  3647.             xcmd=$arg1
  3648.             xargs="$arg2 $extra"
  3649.             case $arg1 in
  3650.             rmail)
  3651.                 from=$othersys!`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
  3652.                 echo -n '     '
  3653.                 grep '^Subject:' $dfile || echo ''
  3654.                 ;;
  3655.             esac
  3656.             ;;
  3657.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra
  3658.             continue ;;
  3659.         esac
  3660.     done
  3661.     echo `wc -c < $dfile`\     $xcmd $xargs $comment \($from\)
  3662.     }
  3663. done
  3664. !Funky!Stuff!
  3665.  
  3666.  
  3667.  
  3668. From: Nancy Blachman <decvax!decwrl!sun!idi!resonex!nancy@Ucb-Vax.ARPA>
  3669. To: net.unix, net.unix-wizards, net.sources
  3670. Subject: Actual tricks, shells, csh aliases and the like, 3 of 3
  3671. Date: 16 Oct 84 21:24:32 GMT
  3672. Organization: Resonex Inc., Sunnyvale, CA
  3673.  
  3674. > [Know anybody with a GREAT .login or .cshrc?]
  3675.  
  3676. > I'm interested in collecting the little tricks, shell scripts, awk
  3677. > hacks, csh aliases, and such that people have built to make their daily
  3678. > life a little easier or more automatic.  Being a fairly new system
  3679. > administrator I don't have the big toolbox that years of messing around
  3680. > will leave you with.  If you have any hacks you're proud of (or that
  3681. > you aren't proud of, but which work anyway), and you're willing to make
  3682. > them public, mail them to me.  I'll collect, collate, shuffle, sort,
  3683. > munge, judge, select and discard them and then "summarize to the net".
  3684.  
  3685. This article centers on C programs and awk scripts I received in response to
  3686. my solicitation.  The first article concentrates on  aliases, and .cshrc and 
  3687. .login files.  The second article in this series focuses shell scripts. 
  3688.  
  3689. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  3690. > Nancy Blachman {allegra,hplabs,ihnp4,sun}!resonex!nancy  (408)720 8600 x37 <
  3691. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  3692.  
  3693. ::::::::::::::
  3694. programs/1
  3695. ::::::::::::::
  3696. Date: Sat, 15 Sep 84 02:45:08 pdt
  3697. From: <hplabs!intelca!t4test!chip>
  3698. To: intelca!hplabs!resonex!nancy
  3699. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  3700.  
  3701. One thing I've put together is a bunch of scripts which give you a
  3702. status line on a DEC type terminal.  The thing is hardwired into VTxxx
  3703. type stuff rather than termcap for two reasons.  First, the cursor
  3704. save/restore function isn't part of termcap.  Secondly, the set
  3705. scrolling region is part of termcap, but it is for VT100 type
  3706. terminals.  Since we only have DEC terminals, it doesn't hurt us too
  3707. much.
  3708.  
  3709. Some history:  I used to like to display my current working directory
  3710. on my prompt line.  Later I wanted my terminal line there too.  (That
  3711. was in case a terminal I was on locked up, I could quickly tell what
  3712. terminal to kill.)  Later, when I had four accounts on the machine I
  3713. thought it would be nice to display my login name in my prompt.  The
  3714. straw which broke the camel's back was that we bought another VAX, and
  3715. I wanted to be able to see which machine I was logged on.  As you might
  3716. imagine, my prompt now extended about 60 columns across the screen.  My
  3717. answer was to take everything out of my prompt except the history
  3718. number and stick it at a status line at the bottom of my screen.
  3719.  
  3720. Below is a shar archive of the status line files.  You do a `source
  3721. stat.init' to get stuff initialized.  Then `son' and `soff' (which are
  3722. aliased to source the two other scripts) turn the status line on and
  3723. off.  These also define a bunch of aliases which help you work with
  3724. programs which don't like the status line.  So, I put a `source
  3725. /usr/public/stat.init' followed by a `son' in my `.login'.  (I don't
  3726. turn it on with my `.cshrc', my shell escapes would then get awfully
  3727. sloooooow.)
  3728.  
  3729. Also, you would need to add `vt100s' and `vt131s' to /etc/termcap.
  3730. This is to keep screen stuff (e.g. more, vi, etc.) happy if you run
  3731. them with the status line on.  This is what I use:
  3732.  
  3733.     ################      VT131 with 24th line reserved
  3734.     ################ d13s|vt131s|VT131S|vt-131s|pt131s|pt-131s|dec
  3735.     vt131s:\
  3736.         :li#23:tc=vt131
  3737.  
  3738. You will definately want to change the terminal identification stuff in
  3739. `stat.init'.  We run Eunice, so I use the `grep' to convert the Unix
  3740. style terminal line identification to a VMS terminal port.  
  3741.  
  3742. You can redefine `statin' in the `stat.init' script to put whatever you 
  3743. want on the status line.
  3744.  
  3745. Well...after all this, I hope you use VT1xx/VT2xx terminals.
  3746. Otherwise, this won't be real exciting.  (Unless you want to rewrite
  3747. `statterm.c')
  3748.  
  3749. ---
  3750.  
  3751. Chip Rosenthal, Intel/Santa Clara
  3752. { idi|intelca|icalqa|kremvax|qubix|ucscc } ! t4test ! { chip|news }
  3753.  
  3754. -----  cut here  -----------------------------------------------------------
  3755.  
  3756. : This is a shar archive.  Extract with sh, not csh.
  3757. : This archive contains the following files
  3758. :  Makefile stat.init stat.on stat.off statterm.c
  3759. : Total number of files: 5
  3760. echo x - Makefile [file 1 of 5]
  3761. sed 's/^|//' > Makefile << '!-FUNKY-STUFF-!'
  3762. |BIN=    /usr/public
  3763. |OBJS=    statterm
  3764. |
  3765. |IOBJS=    $(BIN)/statterm \
  3766. |    $(BIN)/stat.init \
  3767. |    $(BIN)/stat.on \
  3768. |    $(BIN)/stat.off
  3769. |
  3770. |SOURCES=Makefile \
  3771. |    stat.init \
  3772. |    stat.on \
  3773. |    stat.off \
  3774. |    statterm.c
  3775. |
  3776. |all:        $(OBJS)
  3777. |install:    $(IOBJS)
  3778. |shar:        stat.shar
  3779. |
  3780. |statterm:        statterm.c
  3781. |            cc -O statterm.c -o statterm
  3782. |
  3783. |$(BIN)/statterm:    statterm
  3784. |            cp $? $@
  3785. |            chmod 755 $@
  3786. |
  3787. |$(BIN)/stat.init:    stat.init
  3788. |            cp $? $@
  3789. |            chmod 755 $@
  3790. |
  3791. |$(BIN)/stat.on:        stat.on
  3792. |            cp $? $@
  3793. |            chmod 755 $@
  3794. |
  3795. |$(BIN)/stat.off:    stat.off
  3796. |            cp $? $@
  3797. |            chmod 755 $@
  3798. |
  3799. |stat.shar:        $(SOURCES)
  3800. |            shar $(SOURCES) > $@
  3801. |
  3802. |
  3803. !-FUNKY-STUFF-!
  3804. echo x - stat.init [file 2 of 5]
  3805. sed 's/^|//' > stat.init << '!-FUNKY-STUFF-!'
  3806. |alias a 'alias'
  3807. |
  3808. |# run statterm to verify terminal can do status line
  3809. |statterm
  3810. |if $status then
  3811. |    # status line not available on this terminal -- see if a
  3812. |    # baseterm is defined.  if so, then maybe $TERM is just
  3813. |    # messed up from earlier invocation of stat.init.
  3814. |    if $?baseterm then
  3815. |    # baseterm has been defined -- see if it will work
  3816. |    set temp=$TERM
  3817. |    setenv TERM $baseterm
  3818. |    statterm
  3819. |    if $status then
  3820. |        # nope -- baseterm will not work either
  3821. |        setenv TERM $temp
  3822. |        unset temp
  3823. |        goto failed
  3824. |    else
  3825. |        # yes -- baseterm will work
  3826. |        echo "changing terminal type from $temp to $TERM"
  3827. |        unset temp
  3828. |    endif
  3829. |    else
  3830. |    # no baseterm defined
  3831. |    goto failed
  3832. |    endif
  3833. |endif
  3834. |
  3835. |# status line will work with this terminal
  3836. |set baseterm=$TERM
  3837. |set ignoreeof
  3838. |
  3839. |# find user's system (ick)
  3840. |set system=`tr '[A-Z]' '[a-z]' < /usr/include/whoami`
  3841. |
  3842. |# find user's tty (ick ick ick)
  3843. |set temp=`tty`'$'
  3844. |set tty=`grep "$temp" /etc/dev.com | sed -e 's/^.*_\(.*\):.*/\1/'`
  3845. |unset temp
  3846. |
  3847. |# setup terminal strings
  3848. |set statin="`statterm in '${system}\\!${user}' '(${tty})'`" 
  3849. |set statout="`statterm out`" 
  3850. |set statoff="`statterm off`"
  3851. |echo -n "$statoff"
  3852. |
  3853. |# setup status commands
  3854. |#   son - turn on status mode
  3855. |#   soff - turn off status mode
  3856. |#   stat - draw status line
  3857. |#   nostat - erase status line
  3858. |#   termstat - setenv the terminal with status line protected
  3859. |#   termnorm - setenv the terminal without a status line
  3860. |#   ns - execute a command without a status line
  3861. |a son        'source /usr/public/stat.on'
  3862. |a soff        'source /usr/public/stat.off'
  3863. |a stat        ';'
  3864. |a nostat    ';'
  3865. |a termstat    ';'
  3866. |a termnorm    ';'
  3867. |a ns        'nostat ; termnorm ; \!* ; termstat ; stat ; echo ""'
  3868. |
  3869. |# alias the commands which maintain the status line
  3870. |a cd        'chdir \!* ; stat'
  3871. |a popd        'popd ; stat'
  3872. |a pushd        'pushd \!* ; stat'
  3873. |
  3874. |# alias the commands which (might) munch the status line
  3875. |a clear        'clear \!* ; stat'
  3876. |a mail        'mail \!* ; stat'
  3877. |a more        'more \!* ; stat'
  3878. |
  3879. |# alias the commands which should be done with the status line off
  3880. |a lo        'ns logout \!*'
  3881. |a LO        'ns logout \!*'
  3882. |a rn        'ns /local/bin/rn \!*'
  3883. |a pn        'ns /local/bin/pn \!*'
  3884. |a reply        'ns /local/bin/reply \!*'
  3885. |a sus        'ns suspend \!*'
  3886. |a vi        'ns /usr/ucb/vi \!*'
  3887. |a view        'ns /usr/ucb/view \!*'
  3888. |
  3889. |# that is all folks.  the status stuff is initialized
  3890. |# now all you need is a 'son' to turn it on
  3891. |exit 0
  3892. |
  3893. |failed:
  3894. |set baseterm=$TERM
  3895. |set temp="status line is not available for terminal type $TERM"
  3896. |echo $temp
  3897. |set statin=";"
  3898. |set statout=";"
  3899. |if     $?statoff == 0 then
  3900. |    set statoff=";"
  3901. |endif
  3902. |alias son echo "$temp"
  3903. |alias off 'source /usr/public/stat.off'
  3904. |unset temp
  3905. |soff
  3906. |exit 1
  3907. |
  3908. !-FUNKY-STUFF-!
  3909. echo x - stat.on [file 3 of 5]
  3910. sed 's/^|//' > stat.on << '!-FUNKY-STUFF-!'
  3911. |a stat        'echo -n "${statin}${cwd}${statout}"'
  3912. |a nostat    'echo -n "$statoff"'
  3913. |a termstat    'setenv TERM ${baseterm}s'
  3914. |a termnorm    'setenv TERM $baseterm'
  3915. |termstat
  3916. |stat
  3917. |echo ""
  3918. |set statmode
  3919. !-FUNKY-STUFF-!
  3920. echo x - stat.off [file 4 of 5]
  3921. sed 's/^|//' > stat.off << '!-FUNKY-STUFF-!'
  3922. |setenv TERM $baseterm
  3923. |echo -n "$statoff"
  3924. |unset statmode
  3925. |a termstat    ';'
  3926. |a termnorm    ';'
  3927. |a stat ';'
  3928. |a nostat ';'
  3929. !-FUNKY-STUFF-!
  3930. echo x - statterm.c [file 5 of 5]
  3931. sed 's/^|//' > statterm.c << '!-FUNKY-STUFF-!'
  3932. |/*
  3933. | * FILE:    statterm
  3934. | * VERSION:    V0.01 [preliminary]
  3935. | * DATE:    Mon Aug 27 16:43:13 PDT 1984
  3936. | * AUTHOR:      Chip Rosenthal/Intel Corporation
  3937. | * ADDRESS:    t4test!chip
  3938. | * PACKAGE:     'stat' terminal status line package
  3939. | * DESCRIPTION:    produces terminal escape sequences to implement status line
  3940. | * COMPILATION: cc -C statterm.c -o statterm
  3941. | *
  3942. | * REVISION NOTES:
  3943. | *
  3944. | * V1.00  Original program.
  3945. | *
  3946. | *
  3947. | * USAGE:
  3948. | *
  3949. | *    statterm 
  3950. | *        Verifies that the status line will work with current terminal.
  3951. | *        Returns a zero exit status if it will, nonzero if it won't.
  3952. | *
  3953. | *    statterm in [arg ...]
  3954. | *        Creates a string which opens up the status line.  Any
  3955. | *        arguments are placed at the beginning of the status
  3956. | *        line, and the cursor is left there.
  3957. | *
  3958. | *    statterm out
  3959. | *        Create string which closes the status line and returns
  3960. | *        cursor to position it was in prior to the last execution
  3961. | *        of a 'statterm in' string.
  3962. | *
  3963. | *    statterm off
  3964. | *        Creates a string which removes the status line.
  3965. | *
  3966. | *
  3967. | *    EXAMPLE:
  3968. | *        # this is a cshell script
  3969. | *        statterm 
  3970. | *        if $status then
  3971. | *            echo "status line will not work on this terminal"
  3972. | *            exit
  3973. | *        endif
  3974. | *        echo -n `statterm in $user`
  3975. | *        echo -n `pwd`
  3976. | *        echo `statterm out`
  3977. | *
  3978. | *
  3979. | * BUGS:       
  3980. | *
  3981. | *    This program is hardwired into the DEC VT100 terminal escape sequences.
  3982. | *    This is done because (unfortunately) 'termcap' doesn't offer a cursor
  3983. | *    position save/restore feature.
  3984. | *
  3985. | */
  3986. |
  3987. |#include <stdio.h>
  3988. |#define strmatch(A,B) (strcmp((A),(B))==0)
  3989. |
  3990. |/*
  3991. | * VT100 Terminal Escape Definitions -- all parameters are strings
  3992. | */
  3993. |#define ESC           putchar(27);              /* escape character          */
  3994. |#define CSI           ESC;putchar('[');         /* command string            */
  3995. |#define DECSC           ESC;putchar('7');         /* save cursor position      */
  3996. |#define DECRC           ESC;putchar('8');         /* restore cursor position   */
  3997. |#define CUP(L,C)      CSI;printf("%s;%sH",L,C); /* set cursor to line/col    */
  3998. |#define CUU1          CSI;printf("1A");        /* cursor up one line        */
  3999. |#define CUD1          CSI;printf("1B");        /* cursor down one line      */
  4000. |#define EL(MODE)      CSI;printf("%sK",MODE);   /* erase line                */
  4001. |#define ED(MODE)      CSI;printf("%sJ",MODE);   /* erase display             */
  4002. |#define DECSETBM(T,B) CSI;printf("%s;%sr",T,B); /* top/bot of scroll area    */
  4003. |/*
  4004. | * erasing modes:
  4005. | *   mode "0" - from cursor to end
  4006. | *   mode "1" - from beginning to cursor
  4007. | *   mode "2" - entire
  4008. | */
  4009. |
  4010. |
  4011. |main(argc,argv)
  4012. |int argc;
  4013. |char *argv[];
  4014. |{
  4015. |    char *term, *getenv();
  4016. |    int i;
  4017. |
  4018. |    if ( argc == 1 ) {
  4019. |    term=getenv("TERM");
  4020. |    if ( term == NULL )
  4021. |        exit(1);
  4022. |    if ( strmatch(term,"vt100") || strmatch(term,"vt131") )
  4023. |        exit(0);
  4024. |    else
  4025. |        exit(1);
  4026. |    }
  4027. |
  4028. |    if ( strmatch(argv[1],"in") ) {
  4029. |    /*
  4030. |     * Save cursor position, go to line 24, print out the arguments, and
  4031. |     * erase the rest of the status line.  Cursor remains in status line.
  4032. |     */
  4033. |    DECSC;
  4034. |    CUP("24","1");
  4035. |    for ( i=2 ; i<argc ; ++i ) 
  4036. |        printf("%s  ",argv[i]);
  4037. |    EL("0");
  4038. |    } else if ( strmatch(argv[1],"out") ) {
  4039. |    /*
  4040. |     * Protect status line from scrolling and restore cursor to location 
  4041. |     * prior to the last 'in' call.  Move the cursor up and down one line.
  4042. |     * This will keep it out of the status line area if it was there when 
  4043. |     * 'in' was called.
  4044. |     */
  4045. |    DECSETBM("1","23");
  4046. |    DECRC;
  4047. |    CUU1;
  4048. |    CUD1;
  4049. |    } else if ( strmatch(argv[1],"off") ) {
  4050. |    /*
  4051. |     * Save the current cursor position, unprotect the status line, erase 
  4052. |     * the status line, and restore the cursor position.
  4053. |     */
  4054. |    DECSC;
  4055. |    DECSETBM("1","24");
  4056. |    CUP("24","1");
  4057. |    EL("2");
  4058. |    DECRC;
  4059. |    } else
  4060. |    exit(1);
  4061. |
  4062. |}
  4063. !-FUNKY-STUFF-!
  4064. exit
  4065.  
  4066.  
  4067.  
  4068. ::::::::::::::
  4069. programs/2
  4070. ::::::::::::::
  4071. From: ihnp4!mcnc!malloy@ittral
  4072. Date: Thu, 13 Sep 84 21:35:18 edt
  4073. To: ihnp4!resonex!nancy@mcnc
  4074. Subject: Tricks
  4075.  
  4076. Well it depends upon what you mean. The big problem with having lots of aliases
  4077. and such is they start taking up large amounts of memory.  Take it from someone
  4078. who knows.  But here's a few things.  Some you no doubt already have, and most
  4079. are trivial, but it's better to be complete then to leave anything out.  You
  4080. can always just delete this.    == William P. Malloy (ittral!malloy}
  4081. ---------------------------------------------------------------------
  4082. In a .cshrc, a warning and a work around.  Apparently not known by most people
  4083. but obvious to people have who been around.  Our users keep bumping into it
  4084. about once a year like clock work.
  4085. # reason for setting variables only if a prompt already exists
  4086. # If it sets prompt in a non-interactive shell, for instance vi(1)
  4087. # firing up a sub-shell to expand shell meta-characters, the set prompt
  4088. # will stomp on alot of shell variables used for the expansion (like ~)
  4089. #
  4090. if ( $?prompt ) then
  4091.    set mail=/usr/spool/mail/malloy
  4092.    set prompt=\`
  4093.    set histchars=",;"
  4094. endif
  4095. Note the setting of histchars.  A little known, but for me much loved feature
  4096. of csh is the ability to change the history characters "!^" from their default
  4097. values.  The pair `,;' are easier to reach, don't require shifting, and don't
  4098. appear in mail paths.  Typing `mail mcnc\!ihnp4\!resonex\!nancy' gets to be
  4099. a pain every time you want to mail someone.
  4100.  
  4101. alias , 'redo \,* ~/.cmd ~/.cmd1 ; source ~/.cmd1 '
  4102.  
  4103. This little alias allows you to have command editing in the csh.  It's quite
  4104. useful, particularly when you've got a LONG painful command line.  The , is
  4105. just the history character and is ! for most people.  The command redo is a
  4106. simple C program.
  4107. --------------- redo.c  -------------------
  4108. #include <stdio.h>
  4109.  
  4110. /* redo -- outputs a command file (last arg )used to edit and 
  4111.    re-ex a command.  Next to last arg is dest file of the command. 
  4112.  
  4113.    NOTE: if you use a non-standard history character, i.e. not !
  4114.    then you must `setenv HISTCHARS $histchars' in your .login
  4115.    If you do not `set histchars=",;"' for instance then it will
  4116.    automagically default to !    -- 12/2/83 wpm
  4117.  
  4118.    First arg is the history ref . To use:
  4119.     alias , 'redo \,* ~/cmd ~/cmd1 ; source ~/cmd1 '
  4120.     , 25    to edit & re-execute ,25
  4121.     , , or ,  to edit & re-execute ,,
  4122.     , v     to edit & re-execute ,v ,etc. 
  4123.     
  4124. */
  4125.  
  4126. main(argc, argv)
  4127.    int argc;
  4128.    char *argv[];
  4129. {
  4130.    FILE *fp;
  4131.    char *t, *getenv();
  4132.  
  4133.    fp = fopen(argv[argc-1], "w");
  4134.    if ((t = getenv("HISTCHARS")) != NULL)
  4135.       t[1] = '\0';
  4136.    else
  4137.       t = "!";
  4138.    fprintf(fp, "echo \"%s", t);
  4139.    if ( (argc < 4) || (strcmp(argv[1], t) == 0) )
  4140.       fputs("-2", fp);
  4141.    else 
  4142.       fputs(argv[1], fp);
  4143.    fputs(":q\" >! ", fp);
  4144.    fputs(argv[argc-2], fp);
  4145.    putc('\n', fp);
  4146.    fputs("ex +open ", fp);
  4147.    fputs(argv[argc-2], fp);
  4148.    putc('\n', fp);
  4149.    fputs("/usr/local/typein2 < ", fp);
  4150.    fputs(argv[argc-2], fp);
  4151.    putc('\n', fp);
  4152.    fclose(fp);
  4153.    exit(0);
  4154. }
  4155. ------------------ (end of redo.c, begining of typein2.c) --------------------
  4156. #include <stdio.h>
  4157. #include <sgtty.h>
  4158.  
  4159. main(argc, argv)
  4160.     int argc;
  4161.     char **argv;
  4162. {
  4163.     register char *cp;
  4164.     struct sgttyb stb, stb2;
  4165.     int pendin = LPENDIN;
  4166.     int c,i,j;
  4167.     char buff[2];
  4168.     char buff2[256];
  4169.  
  4170.     i=0;
  4171.     while ((c=getchar()) != EOF) {
  4172.             buff2[i++]=c;
  4173.     }
  4174.     ioctl(2, TIOCGETP, &stb);
  4175.     stb2 = stb;
  4176.     stb.sg_flags &= ~ECHO;
  4177.     ioctl(2, TIOCSETN, &stb);
  4178.     for (j=0; j<i; j++) {
  4179.             ioctl(2, TIOCSTI, &buff2[j]);
  4180.             putchar(buff2[j]);
  4181.     }
  4182.     ioctl(2, TIOCSETN, &stb2);
  4183.     ioctl(2, TIOCLBIS, &pendin);
  4184.     exit(0);
  4185. }
  4186. ---------------------------- (end of typein2.c) ------------------------
  4187. A couple of oldies but still the simplest.  cd and back aliases.
  4188. alias back 'set back=$old; set old=$cwd; cd $back; unset back; dirs'
  4189. alias cd 'set old=$cwd; chdir \,*; set prompt = "< $cwd:t > "'
  4190.  
  4191. # this is a useful feature for vi
  4192. setenv EXINIT 'map #1 Gi/\<A\>"add@a|map #2 1G\!Gvispell|set ai sw=3'
  4193.  
  4194. You f2 key will run a file through the spell program, and put the words it
  4195. doesn't find in the dictionary at the bottom of the file.  Then typing f1 will
  4196. cause it to delete the last line in the file, and search for the string in
  4197. the rest of the file.
  4198. ------------------------------ (source for vispell) -------------
  4199. #! /bin/sh
  4200. #
  4201. tee /tmp/vis$$
  4202. echo SpellingList
  4203. spell /tmp/vis$$
  4204. rm /tmp/vis$$
  4205. ------------------------------- (end of vispell) ------------------
  4206. Stuff from our /.cshrc file.  psa lets you see what's going on in the system
  4207. and what people are doing.  Useful to see if people are hanging themselves.
  4208. alias psa 'ps axu | sed "/getty/d" | sort -f | more'
  4209.  
  4210. A simple alias to compile C programs (C adm.c expands to cc adm.c -o adm).
  4211. alias C 'cc \,:* -o \,^:r'
  4212.  
  4213. Useful to see what's going on in the system without those !@#$% bells.
  4214. alias moremsgs "tr -d '\07' </usr/adm/messages | more"
  4215.  
  4216. Like fg.
  4217. alias pj '%-'
  4218.  
  4219. A feature we use in our root .cshrc allowing indivual superusers to get their
  4220. own enviornment.  Useful if people want their own enviornment anywhere people
  4221. share an account.
  4222. if ( $user == "malloy" ) then
  4223.    source /t/malloy/.root
  4224. endif
  4225.  
  4226. --------------- (here's some things I picked up off the net) --------------
  4227. From: ittvax!decvax!harpo!utah-cs!seismo!hao!denelcor!udenva!koala!aburt
  4228. Date: Fri Aug 10 09:19:37 1984
  4229. Subject: Perversions of source -h and other csh aliases
  4230. Newsgroups: net.unix,net.unix-wizards,net.sources
  4231.  
  4232. For your enjoyment, here are some interesting lunch hour csh aliases that 
  4233. I've created.
  4234. {this is to slow, my version is a little faster}
  4235. My personal favorite is the "history editor" -- allows you to edit
  4236. you csh history.  The alias:
  4237.  
  4238.     alias hed history -h !* > $hed; vi + $hed; source -h $hed
  4239.  
  4240. will allow you to invoke 'vi' on your current history.  (If, for
  4241. instance, you typed in a long, tedious line and put in an extra space,
  4242. among other things.  The ^...^...  mechanism to remove it can be quite
  4243. tedious; 'hed's is easy.)  Before anyone starts flaming that vi is too
  4244. slow, history can do it (even if it's tough to type and you're prone to
  4245. more typos doing the history), etc. -- if you don't like it, don't use it.
  4246.  
  4247. Hed works particularly well if you move the command in question to the
  4248. end of the file; then '!!' will execute it after you ZZ from vi.  The
  4249. only drawback to this is that it trashes your current event numbers
  4250. (they get incremented during the source -h).  By using 'hed 10' you
  4251. only edit the last 10 entries in your history.  A temp file, which I
  4252. keep in $hed (set to /tmp/hed.$$ from my .login), is used each time for
  4253. the history.  Obvious changes to this are to use /tmp/hed.$$ straight
  4254. out and add "rm /tmp/hed.$$" to the end of the list.  If you don't like
  4255. waiting for the rm, and your /tmp doesn't get cleared out periodically,
  4256. put a # in front of the name to make it a disposable file.
  4257.  
  4258. This may be slower than the vi/emacs mode in the ksh I keep hearing about, but
  4259. it does give the functionality.
  4260.  
  4261. A slight modification to 'hed'...
  4262.  
  4263.     alias hedf history -h !-0:1 > !-0:2; vi + !-0:2; source -h !-0:2
  4264.  
  4265. allows you to specify a file to place the history into instead of a temp
  4266. file.
  4267.  
  4268. Another modification yields:
  4269.  
  4270.     alias heh echo \!* > $hed; vi + $hed; source -h $hed
  4271.  
  4272. Which lets you edit then add to your history a specific history sequence.
  4273. 'Heh' for History edit history.
  4274.  
  4275. By inserting a 'source \!-0:2' before the source -h in any of the
  4276. above has the effect of executing the commands AND placing them on the
  4277. history list (from which we may conclude that 'alias so source \!* ; 
  4278. source -h \!*' is a useful item: it sources a file then places each line
  4279. into your history).
  4280.  
  4281. On rare occasions you'll have to put extra quotes/escapes around things
  4282. when editing the temp file so it gets sourced right.  Particularly around
  4283. aliases with raw history substitutions in them (the \!* type of thing).
  4284. The easiest is to try it first; if it fails, edit it again.  After all,
  4285. two 'hed's are better than one...
  4286.  
  4287. Regarding the use of !-0:1 instead of !:1 for the first argument to the
  4288. current command -- At least one csh is known to accept the former but not
  4289. the latter.  (The same csh dumps core (therefore logging you out) on receipt
  4290. of the !# history selector.  This is version 1.0 of 4.2BSD csh on a Sun-2.
  4291. The 1.1 csh exhibits this behavior:
  4292.  
  4293.     echo a !#
  4294.     a echo a echo
  4295.  
  4296. adding an extra arg 0 to the end.  Is this common to other cshs out there?)
  4297.  
  4298. So, for those whose csh's allow !:1, use that where I have !-0:1, etc.
  4299.  
  4300. Another interesting perversion is an alias'd whereis:
  4301.  
  4302.     alias wheres ls -l \{'`echo $path | sed "s/ /,/g"`'\}/'`echo \!-0:1 | sed "s/^./[&]/"`'
  4303.  
  4304. It does an ls -l on every file (passed as arg 1) in any directory on
  4305. your current path.  (No aliases, though adding an if at the front
  4306. should do the trick.)  The idea is to turn your $path list into a comma
  4307. separates list, stick that between {}, and append / and arg 1 to that.
  4308. Alas, if the file doesn't exist in one of the directories, you get
  4309. errors from ls saying it doesn't exist in a given directory.  So, arg 1
  4310. is turned into a pattern, which is allowed to fail; the pattern is,
  4311. e.g., foo --> [f]oo.  So the second arg to ls only expands to the
  4312. existing files.
  4313. ---------------------------- (end of net article) ------------------------
  4314. --
  4315. Address: William P. Malloy, ITT Telecom, B & CC Engineering Group, Raleigh NC
  4316.      {ihnp4!mcnc, burl, ncsu, decvax!ittvax}!ittral!malloy
  4317.  
  4318.  
  4319. ::::::::::::::
  4320. awk/1
  4321. ::::::::::::::
  4322. Date:       Wed, 19 Sep 84 11:44:38 CST
  4323. From: David Chase <hplabs!ucbvax!rbbb@rice.ARPA>
  4324. Subject:    Re: Tricks, shell and awk scripts, csh aliases and the like
  4325. To: resonex!nancy@BERKELEY
  4326.  
  4327. Here is my favorite awk script.  It turns a list of csrc's from memory
  4328. errors on an 11/780 (with MS780C controller) into board and chip position
  4329. for certain Mostek memory boards.  This script saved me many headaches,
  4330. because the tables in the appendix of the technical manual were hard to read
  4331. and contained errors (errors that were noticed as deviations from a pattern
  4332. when entering this script).
  4333.  
  4334. #
  4335. # Incredible sleazy awk file to attack memory errors
  4336. # Included here is the local configuration, because some decoding
  4337. # is board specific
  4338. BEGIN    {
  4339. # Boards understood by this program
  4340.  
  4341. #    mk4118 = mostek mk8016 fully populated with mk4116 chips (512k)
  4342.     known["mk4118"] = 1
  4343.  
  4344. #    mk4116 = mostek mk8016 half populated with mk4116 chips (256k)
  4345.     known["mk4116"] = 1
  4346.  
  4347. #    mk8016 = mostek mk8016 fully populated with mk4108 chips (256k)
  4348.     known["mk4108"] = 1
  4349.  
  4350. #    m8210 = DEC 256k board; don't know how to decode this guy (256k)
  4351.     known["m8210"] = 0
  4352.  
  4353. # To add different boards, (i.e., not conforming to this system)
  4354. # append to the "pos" map, and make "keys[<array><bank><new board>]"
  4355. # reference the appended chip addresses.
  4356.  
  4357. # Local configuration
  4358. # boards is indexed by slot number
  4359.     boards["0"] = "m8210"
  4360.     boards["1"] = "m8210"
  4361.     boards["2"] = "m8210"
  4362.     boards["3"] = "m8210"
  4363.     boards["4"] = "m8210"
  4364.     boards["5"] = "m8210"
  4365.     boards["6"] = "mk4116"
  4366.     boards["7"] = "mk4116"
  4367.     boards["8"] = "mk4116"
  4368.     boards["9"] = "mk4116"
  4369.     boards["a"] = "mk4116"
  4370.     boards["b"] = "mk4116"
  4371.     boards["c"] = "mk4118"
  4372.     boards["d"] = "mk4118"
  4373.     boards["e"] = "mk4118"
  4374.     boards["f"] = "mk4118"
  4375.     
  4376. #    bit in error for a given CRC calculation
  4377. #    bits are identified by "u" (upper), "l" (lower), and "c" (check)
  4378. #    folowed by the bit number.
  4379.  
  4380.       bit["01"] = "c0"
  4381.       bit["02"] = "c1"
  4382.     bit["04"] = "c2"
  4383.     bit["08"] = "c3"
  4384.     bit["10"] = "c4"
  4385.     bit["19"] = "l01"
  4386.     bit["1a"] = "l02"
  4387.     bit["1c"] = "l04"
  4388.     bit["1f"] = "l07"
  4389.     bit["20"] = "c5"
  4390.     bit["38"] = "l00"
  4391.     bit["3b"] = "l03"
  4392.     bit["3d"] = "l05"
  4393.     bit["3e"] = "l06"
  4394.     bit["40"] = "c6"
  4395.     bit["49"] = "l09"
  4396.     bit["4a"] = "l10"
  4397.     bit["4c"] = "l12"
  4398.     bit["4f"] = "l15"
  4399.     bit["51"] = "l17"
  4400.     bit["52"] = "l18"
  4401.     bit["54"] = "l20"
  4402.     bit["57"] = "l23"
  4403.     bit["58"] = "l24"
  4404.     bit["5b"] = "l27"
  4405.     bit["5d"] = "l29"
  4406.     bit["5e"] = "l30"
  4407.     bit["68"] = "l08"
  4408.     bit["6b"] = "l11"
  4409.     bit["6d"] = "l13"
  4410.     bit["6e"] = "l14"
  4411.     bit["70"] = "l16"
  4412.     bit["73"] = "l19"
  4413.     bit["75"] = "l21"
  4414.     bit["76"] = "l22"
  4415.     bit["79"] = "l25"
  4416.     bit["7a"] = "l26"
  4417.     bit["7c"] = "l28"
  4418.     bit["7e"] = "l31"
  4419.     bit["80"] = "c7"
  4420.     bit["89"] = "u01"
  4421.     bit["8a"] = "u02"
  4422.     bit["8c"] = "u04"
  4423.     bit["8f"] = "u07"
  4424.     bit["91"] = "u09"
  4425.     bit["92"] = "u10"
  4426.     bit["94"] = "u12"
  4427.     bit["97"] = "u15"
  4428.     bit["98"] = "u16"
  4429.     bit["9b"] = "u19"
  4430.     bit["9d"] = "u21"
  4431.     bit["9e"] = "u22"
  4432.     bit["a8"] = "u00"
  4433.     bit["ab"] = "u03"
  4434.     bit["ad"] = "u05"
  4435.     bit["ae"] = "u06"
  4436.     bit["b0"] = "u08"
  4437.     bit["b3"] = "u11"
  4438.     bit["b5"] = "u13"
  4439.     bit["b6"] = "u14"
  4440.     bit["b9"] = "u17"
  4441.     bit["ba"] = "u18"
  4442.     bit["bc"] = "u20"
  4443.     bit["bf"] = "u23"
  4444.     bit["c1"] = "u25"
  4445.     bit["c2"] = "u26"
  4446.     bit["c4"] = "u28"
  4447.     bit["c7"] = "u31"
  4448.     bit["e0"] = "u24"
  4449.     bit["e3"] = "u27"
  4450.     bit["e5"] = "u29"
  4451.     bit["e6"] = "u30"
  4452.  
  4453. #    binary decoding of hex digits
  4454.  
  4455.     hex["0"]  = "0000"
  4456.     hex["1"]  = "0001"
  4457.     hex["2"]  = "0010"
  4458.     hex["3"]  = "0011"
  4459.     hex["4"]  = "0100"
  4460.     hex["5"]  = "0101"
  4461.     hex["6"]  = "0110"
  4462.     hex["7"]  = "0111"
  4463.     hex["8"]  = "1000"
  4464.     hex["9"]  = "1001"
  4465.     hex["a"]  = "1010"
  4466.     hex["b"]  = "1011"
  4467.     hex["c"]  = "1100"
  4468.     hex["d"]  = "1101"
  4469.     hex["e"]  = "1110"
  4470.     hex["f"]  = "1111"
  4471.  
  4472. #    chip positions for a given bit, collected across all possible
  4473. #    boards.  Each group of 3 letters represents a position.
  4474. #    See keys for a better description.
  4475.  
  4476.     pos["u31"] =  "i01h01g01f01"
  4477.     pos["u30"] =  "e01d01c01b01"
  4478.     pos["u29"] =  "i02h02g02f02"
  4479.     pos["u28"] =  "e02d02c02b02"
  4480.     pos["u27"] =  "i03h03g03f03"
  4481.     pos["u26"] =  "e03d03c03b03"
  4482.     pos["u25"] =  "i04h04g04f04"
  4483.     pos["u24"] =  "e04d04c04b04"
  4484.     pos["u23"] =  "a01a02a03a04"
  4485.     pos["u22"] =  "i05h05g05f05"
  4486.     pos["u21"] =  "e05d05c05b05"
  4487.     pos["u20"] =  "i06h06g06f06"
  4488.     pos["u19"] =  "e06d06c06b06"
  4489.     pos["u18"] =  "i07h07g07f07"
  4490.     pos["u17"] =  "e07d07c07b07"
  4491.     pos["u16"] =  "i08h08g08f08"
  4492.     pos["u15"] =  "e08d08c08b08"
  4493.     pos["u14"] =  "a05a06a07a08"
  4494.     pos["u13"] =  "i09h09g09f09"
  4495.     pos["u12"] =  "e09d09c09b09"
  4496.     pos["u11"] =  "i10h10g10f10"
  4497.     pos["u10"] =  "e10d10c10b10"
  4498.     pos["u09"] =  "i11h11g11f11"
  4499.     pos["u08"] =  "e11d11c11b11"
  4500.     pos["u07"] =  "i12h12g12f12"
  4501.     pos["u06"] =  "e12d12c12b12"
  4502.     pos["u05"] =  "a09a10a11a12"
  4503.     pos["u04"] =  "i13h13g13f13"
  4504.     pos["u03"] =  "e13d13c13b13"
  4505.     pos["u02"] =  "i14h14g14f14"
  4506.     pos["u01"] =  "e14d14c14b14"
  4507.     pos["u00"] =  "i15h15g15f15"
  4508.     pos["c7"] =   "e15d15c15b15"
  4509.     pos["c6"] =   "i16h16g16f16"
  4510.     pos["c5"] =   "e16d16c16b16"
  4511.     pos["c4"] =   "a13a14a15a16"
  4512.     pos["l31"] =  "i17h17g17f17"
  4513.     pos["l30"] =  "e17d17c17b17"
  4514.     pos["l29"] =  "i18h18g18f18"
  4515.     pos["l28"] =  "e18d18c18b18"
  4516.     pos["l27"] =  "i19h19g19f19"
  4517.     pos["l26"] =  "e19d19c19b19"
  4518.     pos["l25"] =  "i20h20g20f20"
  4519.     pos["l24"] =  "e20d20c20b20"
  4520.     pos["l23"] =  "a17a18a19a20"
  4521.     pos["l22"] =  "i21h21g21f21"
  4522.     pos["l21"] =  "e21d21c21b21"
  4523.     pos["l20"] =  "i22h22g22f22"
  4524.     pos["l19"] =  "e22d22c22b22"
  4525.     pos["l18"] =  "i23h23g23f23"
  4526.     pos["l17"] =  "e23d23c23b23"
  4527.     pos["l16"] =  "i24h24g24f24"
  4528.     pos["l15"] =  "e24d24c24b24"
  4529.     pos["l14"] =  "a21a22a23a24"
  4530.     pos["l13"] =  "i25h25g25f25"
  4531.     pos["l12"] =  "e25d25c25b25"
  4532.     pos["l11"] =  "i26h26g26f26"
  4533.     pos["l10"] =  "e26d26c26b26"
  4534.     pos["l09"] =  "i27h27g27f27"
  4535.     pos["l08"] =  "e27d27c27b27"
  4536.     pos["l07"] =  "i28h28g28f28"
  4537.     pos["l06"] =  "e28d28c28b28"
  4538.     pos["l05"] =  "a25a26a27a28"
  4539.     pos["l04"] =  "i29h29g29f29"
  4540.     pos["l03"] =  "e29d29c29b29"
  4541.     pos["l02"] =  "i30h30g30f30"
  4542.     pos["l01"] =  "e30d30c30b30"
  4543.     pos["l00"] =  "i31h31g31f31"
  4544.     pos["c3"] =   "e31d31c31b31"
  4545.     pos["c2"] =   "i32h32g32f32"
  4546.     pos["c1"] =   "e32d32c32b32"
  4547.     pos["c0"] =   "a29a30a31a32"
  4548.  
  4549. #    keys is indexed by <board #> <bank> <board type>
  4550. #    and yields an index into  a particular pos string
  4551. #    for example, board 0, bit 0 on an mk4118 board
  4552. #    gives a key of 4.  If the bit in error was c0, then
  4553. #    the chip in error is a32 (from the 4th group of 3
  4554. #    in pos["c0"].  To change this map, create new keys
  4555. #    and (if necessary) append to the pos entries.
  4556. #    If it could be more than one chip, then use a multiple
  4557. #    digit key (e.g, see the keys for the mk4108 board).
  4558.  
  4559.     keys["00mk4118"] = "4"
  4560.     keys["20mk4118"] = "4"
  4561.     keys["40mk4118"] = "4"
  4562.     keys["60mk4118"] = "4"
  4563.     keys["80mk4118"] = "4"
  4564.     keys["a0mk4118"] = "4"
  4565.     keys["c0mk4118"] = "4"
  4566.     keys["e0mk4118"] = "4"
  4567.     keys["01mk4118"] = "2"
  4568.     keys["21mk4118"] = "2"
  4569.     keys["41mk4118"] = "2"
  4570.     keys["61mk4118"] = "2"
  4571.     keys["81mk4118"] = "2"
  4572.     keys["a1mk4118"] = "2"
  4573.     keys["c1mk4118"] = "2"
  4574.     keys["e1mk4118"] = "2"
  4575.     keys["10mk4118"] = "3"
  4576.     keys["30mk4118"] = "3"
  4577.     keys["50mk4118"] = "3"
  4578.     keys["70mk4118"] = "3"
  4579.     keys["90mk4118"] = "3"
  4580.     keys["b0mk4118"] = "3"
  4581.     keys["d0mk4118"] = "3"
  4582.     keys["f0mk4118"] = "3"
  4583.     keys["11mk4118"] = "1"
  4584.     keys["31mk4118"] = "1"
  4585.     keys["51mk4118"] = "1"
  4586.     keys["71mk4118"] = "1"
  4587.     keys["91mk4118"] = "1"
  4588.     keys["b1mk4118"] = "1"
  4589.     keys["d1mk4118"] = "1"
  4590.     keys["f1mk4118"] = "1"
  4591.      
  4592.     keys["00mk4116"] = "4"
  4593.     keys["20mk4116"] = "4"
  4594.     keys["40mk4116"] = "4"
  4595.     keys["60mk4116"] = "4"
  4596.     keys["80mk4116"] = "4"
  4597.     keys["a0mk4116"] = "4"
  4598.     keys["c0mk4116"] = "4"
  4599.     keys["e0mk4116"] = "4"
  4600.     keys["01mk4116"] = "2"
  4601.     keys["21mk4116"] = "2"
  4602.     keys["41mk4116"] = "2"
  4603.     keys["61mk4116"] = "2"
  4604.     keys["81mk4116"] = "2"
  4605.     keys["a1mk4116"] = "2"
  4606.     keys["c1mk4116"] = "2"
  4607.     keys["e1mk4116"] = "2"
  4608.     keys["10mk4116"] = "4"
  4609.     keys["30mk4116"] = "4"
  4610.     keys["50mk4116"] = "4"
  4611.     keys["70mk4116"] = "4"
  4612.     keys["90mk4116"] = "4"
  4613.     keys["b0mk4116"] = "4"
  4614.     keys["d0mk4116"] = "4"
  4615.     keys["f0mk4116"] = "4"
  4616.     keys["11mk4116"] = "2"
  4617.     keys["31mk4116"] = "2"
  4618.     keys["51mk4116"] = "2"
  4619.     keys["71mk4116"] = "2"
  4620.     keys["91mk4116"] = "2"
  4621.     keys["b1mk4116"] = "2"
  4622.     keys["d1mk4116"] = "2"
  4623.     keys["f1mk4116"] = "2"
  4624.      
  4625.     keys["00mk4108"] = "34"
  4626.     keys["20mk4108"] = "34"
  4627.     keys["40mk4108"] = "34"
  4628.     keys["60mk4108"] = "34"
  4629.     keys["80mk4108"] = "34"
  4630.     keys["a0mk4108"] = "34"
  4631.     keys["c0mk4108"] = "34"
  4632.     keys["e0mk4108"] = "34"
  4633.     keys["01mk4108"] = "12"
  4634.     keys["21mk4108"] = "12"
  4635.     keys["41mk4108"] = "12"
  4636.     keys["61mk4108"] = "12"
  4637.     keys["81mk4108"] = "12"
  4638.     keys["a1mk4108"] = "12"
  4639.     keys["c1mk4108"] = "12"
  4640.     keys["e1mk4108"] = "12"
  4641.     keys["10mk4108"] = "34"
  4642.     keys["30mk4108"] = "34"
  4643.     keys["50mk4108"] = "34"
  4644.     keys["70mk4108"] = "34"
  4645.     keys["90mk4108"] = "34"
  4646.     keys["b0mk4108"] = "34"
  4647.     keys["d0mk4108"] = "34"
  4648.     keys["f0mk4108"] = "34"
  4649.     keys["11mk4108"] = "12"
  4650.     keys["31mk4108"] = "12"
  4651.     keys["51mk4108"] = "12"
  4652.     keys["71mk4108"] = "12"
  4653.     keys["91mk4108"] = "12"
  4654.     keys["b1mk4108"] = "12"
  4655.     keys["d1mk4108"] = "12"
  4656.     keys["f1mk4108"] = "12"
  4657.     }
  4658.  
  4659.     {csrc     = $1
  4660.     syndrome = substr (csrc,7,2)
  4661.     board    = substr (csrc,2,1)
  4662.     boardtype = boards[board]
  4663.     bank     = substr (hex [substr (csrc,3,1)],1,1)
  4664.     chips    = bit[syndrome]
  4665.     if (known[boardtype])
  4666.     {  where     = pos[chips]
  4667.        key     = keys[board bank boardtype]
  4668.        sbegin   = 3 * (substr(key,1,1) - 1) + 1
  4669.        thechip  = substr(where,sbegin,3)
  4670.        if (length(key) > 1) 
  4671.        {   sbegin   = 3 * (substr(key,2,1) - 1) + 1
  4672.            thechip  = thechip " and/or " substr(where,sbegin,3)
  4673.        }
  4674. #       printf "\n"
  4675. #       print "csrc =      "    csrc
  4676. #       print "syndrome =  "    syndrome
  4677. #       print "board =     "    board
  4678. #       print "bank =      "    bank
  4679. #       print "chips =     "    chips
  4680. #       print "locations = "    where
  4681. #       print "boardtype = " boardtype
  4682. #       print "key =       " key
  4683. #       print "the chip is "    thechip
  4684.        errors[board "-" thechip]++;
  4685.     }
  4686.     else 
  4687.     {
  4688. #       printf "\n"
  4689. #       print "Board type " boardtype " is unknown"
  4690.        errors["unknown-unknown"]++;
  4691.     }
  4692. }
  4693.     
  4694. END { for (i in errors) {
  4695.     n = split(i,list,"-");
  4696.     printf "%d errors for board %s, chip %s\n",errors[i],list[1],list[2];
  4697.     }
  4698. }
  4699.  
  4700.