home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / kashe < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  18.7 KB

  1. From decwrl!sun-barr!cs.utexas.edu!uunet!allbery Thu Aug  3 08:51:55 PDT 1989
  2. Article 1001 of comp.sources.misc:
  3. Path: decwrl!sun-barr!cs.utexas.edu!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i109: kashe - change directory by menu
  7. Message-ID: <61771@uunet.UU.NET>
  8. Date: 29 Jul 89 00:54:46 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: jack@cs.glasgow.ac.uk
  11. Lines: 701
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 7, Issue 109
  15. Submitted-by: jack@cs.glasgow.ac.uk
  16. Archive-name: kashe
  17.  
  18. The following stuff saves me a LOT of typing directory names.  Needs the
  19. Korn shell.  I've been using it unchanged for months, but it's only been
  20. tested on Sun 3 machines.  Much easier to use than to describe.
  21.  
  22. RTFM before trying to use it - it helps to have 'lc', and your environment
  23. needs to be set up right.  The details on using it if ksh isn't your login
  24. shell are there to help proselytize for ksh among users of other shells.
  25.  
  26. best wishes - jack
  27.  
  28. #--------------------------------CUT HERE-------------------------------------
  29. #! /bin/sh
  30. #
  31. # This is a shell archive.  Save this into a file, edit it
  32. # and delete all lines above this comment.  Then give this
  33. # file to sh by executing the command "sh file".  The files
  34. # will be extracted into the current directory owned by
  35. # you with default permissions.
  36. #
  37. # The files contained herein are:
  38. #
  39. # -rw-r-----  1 jack         9439 Jul 28 19:10 kashe.1
  40. # -rw-r-----  1 jack         6819 Jul 28 19:24 .kshenv
  41. #
  42. echo 'x - kashe.1'
  43. if test -f kashe.1; then echo 'shar: not overwriting kashe.1'; else
  44. sed 's/^X//' << '________This_Is_The_END________' > kashe.1
  45. X.TH KASHE 1 "7 January 1989" "Jack Campin" "KSH(1) FUNCTIONS"
  46. X
  47. X.SH NAME
  48. X
  49. Xu, d, c, g, p, csort, cdrop, cwipe, csave, cload, cgrep, chelp \- quicker ways
  50. Xto change directory
  51. X
  52. X.SH SYNOPSIS
  53. X
  54. X.B u
  55. X.LP
  56. X.B d
  57. X[
  58. X.I directory
  59. X]
  60. X.LP
  61. X.B c
  62. X[
  63. X.I directory
  64. X]
  65. X.LP
  66. X.B g
  67. X.I number
  68. X.LP
  69. X.B p
  70. X.I pattern
  71. X.LP
  72. X.B csort
  73. X.LP
  74. X.B cdrop
  75. X.LP
  76. X.B cwipe
  77. X[
  78. X.I pattern
  79. X]
  80. X.LP
  81. X.B csave
  82. X[
  83. X.I file
  84. X]
  85. X.LP
  86. X.B cload
  87. X[
  88. X.I file
  89. X]
  90. X.LP
  91. X.B cgrep
  92. X.I pattern
  93. X.LP
  94. X.B chelp
  95. X
  96. X.SH DESCRIPTION
  97. X
  98. XThis is a collection of Korn shell (
  99. X.I ksh (1)
  100. X) functions I wrote after having to
  101. Xswitch between different directories a lot.  I am a pretty hopeless typist,
  102. Xand even with
  103. X.I ksh's
  104. Xcommand-edit-and-retry features, it was getting boring
  105. Xentering something like
  106. X
  107. X.br
  108. X    cd /bakcuppisa/users/jack/oscar/parse
  109. X
  110. Xand then having to change the "kc" to "ck".
  111. X
  112. XSo these functions give you a zippy menu interface to
  113. X.I cd.
  114. XTheir rationale is that most people most of the time only switch between a
  115. Xrelatively small "working set" of directories; these functions are intended to
  116. Xmake this set easily accessible.  By far the most frequent commands in Unix are
  117. X.I cd, pwd,
  118. Xand
  119. X.I ls;
  120. Xthese functions improve the interface to all of these.  I use them together
  121. Xwith a prompt line that displays my current directory, hence the "<pathname>\ $
  122. X" prompts below.  The functions fall into two groups; the first maintains a
  123. Xcache of "interesting" directories, which you might use like this (assuming
  124. Xthe 3 directories below are in the cache already):
  125. X
  126. X.br
  127. X    /pisa/users/jack $ c
  128. X.br
  129. X    1) /usr/spool/news/comp/binaries/mac
  130. X.br
  131. X    2) /usr/lib/tex
  132. X.br
  133. X    3) /backuppisa/users/jack
  134. X.br
  135. X    4) New...
  136. X.br
  137. X    number? 1
  138. X.br
  139. X    /usr/spool/news/comp/binaries/mac $
  140. X
  141. XThose directories might have got there by the following session, starting from
  142. Xempty:
  143. X
  144. X.br
  145. X    /pisa/users/jack $ c
  146. X.br
  147. X    directory? /usr/spool/news/comp/binaries/mac
  148. X.br
  149. X    /usr/spool/news/comp/binaries/mac $ cd /usr/lib
  150. X.br
  151. X    /usr/lib $ c tex
  152. X.br
  153. X    /usr/lib/tex $ cd /backuppisa/users/jack
  154. X.br
  155. X    /backuppisa/users/jack $ c
  156. X.br
  157. X    1) /usr/spool/news/comp/binaries/mac
  158. X.br
  159. X    2) /usr/lib/tex
  160. X.br
  161. X    3) New...
  162. X.br
  163. X    number? 3
  164. X.br
  165. X    directory? .
  166. X.br
  167. X    /backuppisa/users/jack $ cd
  168. X.br
  169. X    /pisa/users/jack $
  170. X
  171. XExtra items can be added at any time.  Directories can be specified any way
  172. Xyou like, including tilde aliases.  Directories in the cache are represented
  173. Xby absolute pathname.
  174. X.PP
  175. XThus
  176. X.B c
  177. Xhas three modes of operation -
  178. X.I cd
  179. Xto a cached directory by menu; add a new one to the cache when prompted and
  180. X.I cd
  181. Xto it; or add
  182. X.I directory
  183. Xto the cache and
  184. X.I cd
  185. Xto it, sidestepping the menu.  Only valid directories can be added this way.
  186. XThus you can use it where you would previously have used
  187. X.I cd,
  188. Xto load your cache.
  189. X.PP
  190. XThere is also a "goto" for use when you know the menu item number you want
  191. X(typically, just after you've typed the wrong number to
  192. X.B c
  193. Xand still have the menu in front of you):
  194. X
  195. X.br
  196. X    /pisa/users/jack $ g 2
  197. X.br
  198. X    /usr/lib/tex $
  199. X
  200. XAnd a "goto by pattern" which scans the cache looking for a match:
  201. X
  202. X.br
  203. X    /usr/lib/tex $ p mac
  204. X.br
  205. X    /usr/spool/news/comp/binaries/mac $
  206. X
  207. X.B  p
  208. Xwill give you a menu if more than one directory in the cache matches the
  209. Xpattern.  The pattern syntax is as for
  210. X.I egrep (1).
  211. XYou will usually be able to find a very short string that uniquely identifies
  212. Xyour target.  I find this more useful than
  213. X.B g.
  214. X.PP
  215. X.B csort
  216. Xsorts the cache, eliminating duplicated entries.
  217. X.B cdrop
  218. Xdeletes directories from it; enter the numbers of the items to delete when
  219. Xprompted.
  220. X.B cwipe
  221. Xwill either clear it completely, or, if given a pattern argument, will just
  222. Xremove items matching that pattern.
  223. X.B csave
  224. Xsaves the cache to a file.
  225. X.B cload
  226. Xreloads it, appending the file to your current cache.
  227. X.PP
  228. XA less generally useful function in the same group,
  229. X.B cgrep,
  230. Xtakes a string and adds to the
  231. Xcache all accessible directories below your current directory whose pathnames
  232. Xhave a last component containing that string.  It then gives you a menu
  233. Xlike
  234. X.B c.
  235. XIt's intended for finding your way around pieces of software
  236. Xthat scatter themselves in undocumented places all over the file system but use
  237. Xrelated names for all those places.  You won't use this often, and it's slow
  238. X(because of the
  239. X.I ls -R
  240. Xembedded in it) but it will save you much frustration with
  241. X.I find
  242. Xand the like on the rare occasions when you want
  243. Xit.  The string is an
  244. X.I egrep
  245. Xpattern.  Since
  246. X.B cgrep
  247. Xembeds the string in a larger search pattern, some patterns will not work, in
  248. Xparticular those containing "^" or "$" as unescaped metacharacters, or "/".
  249. X.B cgrep
  250. X"" puts the entire tree below the current directory into the cache.
  251. X.PP
  252. XYou can ^C out of a menu selection leaving your directory unchanged.  The
  253. Xcache is kept in a shell variable, so changes to it will not persist when
  254. Xreturning from a subshell unless you
  255. X.B csave
  256. Xbefore exiting and then
  257. X.B cload
  258. Xin the outer shell.
  259. X.PP
  260. XThe second group is a pair of functions that tries to emulate the way you move
  261. Xaround the file system on the Mac - a function
  262. X.B u
  263. Xto go up and
  264. X.B d
  265. Xto go down.  (Originally inspired by my infuriatingly frequent typing of "cd.."
  266. Xfor "cd ..").  It's usually a lot more convenient to use
  267. X.B d
  268. Xin "unknown territory" than to manually list subdirectories and then do
  269. X.I cd;
  270. Xfor one thing,
  271. X.B d
  272. Xfilters out non-directories from its display.  If the target directory has no
  273. Xsubdirectories,
  274. X.B d
  275. Xacts like
  276. X.I cd.
  277. XThere are two alternative forms of
  278. X.B d
  279. Xprovided depending on whether the fast file lister
  280. X.I lc,
  281. X(written by gamiddleton@watmath.uucp and posted to comp.sources.unix in
  282. X1987) is available; comment out the one you don't want.
  283. X.PP
  284. XFinally,
  285. X.B chelp
  286. Xprints out a command synopsis.
  287. X.PP
  288. XBy using both groups of functions, you can move to any point in the file
  289. Xsystem without ever typing a directory name, and get back to it from anywhere
  290. Xwith four or five keystrokes.
  291. X
  292. X.SH ENVIRONMENT
  293. X
  294. XTo get all these into your environment, put them into a file called, say,
  295. X.I .kshenv.
  296. XThe Korn shell finds this file from the variable
  297. X.B ENV.
  298. X(
  299. X.B chelp
  300. Xuses
  301. X.B ENV
  302. Xto find the text it displays.)  The file read or written by
  303. X.B cload
  304. Xand
  305. X.B csave
  306. Xis specified by the filename parameter if one is given; if not, by
  307. X.B KSHDIRFILE
  308. Xif that is set; and as a default, the file
  309. X.I .kshenvdirs
  310. Xin the home directory (this is OK if you always use the same domain).  These
  311. Xfunctions use a shell variable
  312. X.B NL
  313. Xwhich should always contain a newline.  This is simply to make the code easier
  314. Xto read.
  315. X.PP
  316. XHow you set up this environment depends on what
  317. Xyour login shell is.
  318. X
  319. X.PP
  320. X.B Korn shell:
  321. Xadd the lines
  322. X
  323. X.br
  324. X    ENV=.kshenv \ \ export ENV
  325. X.br
  326. X    KSHDIRFILE=~/.`domainname`-dirs \ \ export KSHDIRFILE
  327. X
  328. Xto your
  329. X.I .profile.
  330. XTo get the prompt line, also add
  331. X
  332. X.br
  333. X    PS1='${PWD} $' \ \ export PS1
  334. X.PP
  335. XTo preload the cache at login time, also add to your
  336. X.I .profile
  337. Xthe lines
  338. X
  339. X.br
  340. X    .\ \ $ENV
  341. X.br
  342. X    cload
  343. X
  344. X.PP
  345. X.B C shell:
  346. Xadd the lines
  347. X
  348. X.br
  349. X    setenv ENV .kshenv
  350. X.br
  351. X    setenv KSHDIRFILE \ \  ~/.`domainname`-dirs
  352. X
  353. Xto your
  354. X.I .login
  355. Xand add
  356. X
  357. X.br
  358. X    PS1='${PWD} $' \ \ export PS1
  359. X
  360. Xto your
  361. X.I .kshenv.
  362. X
  363. X.PP
  364. X.B Bourne shell:
  365. Xadd the lines
  366. X
  367. X.br
  368. X    ENV=.kshenv \ \ export ENV
  369. X.br
  370. X    KSHDIRFILE=~/.`domainname`-dirs \ \ export KSHDIRFILE
  371. X
  372. Xto your
  373. X.I .profile
  374. Xand add
  375. X
  376. X.br
  377. X    PS1='${PWD} $' \ \ export PS1
  378. X
  379. Xto your
  380. X.I .kshenv.
  381. X
  382. X.SH FILE FORMAT
  383. X
  384. XA cache file is simply a list of full pathnames of directories terminated by
  385. Xnewlines.
  386. X
  387. X.SH DIAGNOSTICS
  388. X
  389. XError messages are printed if these functions are called with the wrong number
  390. Xof parameters, if files can't be read or written, or if commands used by the
  391. Xfunctions fail.  The exit code returned is 1 when a failure or a signal is
  392. Xdetected, otherwise 0.
  393. X
  394. X.SH BUGS
  395. X
  396. XIf you have more directories in the cache than will fit on the screen
  397. X(this might happen after using
  398. X.B cgrep
  399. X) you'll have problems seeing them with
  400. X.B c
  401. Xor
  402. X.B cdrop.
  403. XThere is no way to avoid this as far as I know.  The workaround is to
  404. X.B csave,
  405. Xedit the file, and then
  406. X.B cload
  407. Xagain.
  408. X.PP
  409. XYou will sometimes get insane error messages if you enter random
  410. Xstrings instead of numbers.  This is
  411. X.I ksh's
  412. Xfault and nothing can be done about it.
  413. X.PP
  414. XThese functions don't handle directory names with embedded newlines.  Embedded
  415. Xspaces are OK, though; embedded tabs are invisible in the menus but otherwise
  416. Xseem to work (and if you embed tabs in directory names you deserve to have
  417. Xproblems, anyway).
  418. X.PP
  419. XIf anyone has bug reports or ideas for improvement, let me know.  I suspect
  420. Xsymbolic links may not be handled quite right, but haven't found a definite
  421. Xbug there yet.  The same ideas can be used for maintaining caches of strings
  422. Xin general; it would not be trivial to modify these into a general-purpose
  423. Xstring cache manager but might be worth doing someday.
  424. X.PP
  425. XAn undo facility would be easy enough to add; anyone want it?
  426. X
  427. X.SH KLUDGE
  428. X
  429. XYou need multiple cache files if you log in from more than one server, given
  430. Xthe inconsistencies in Glasgow's present NFS naming scheme - the same
  431. Xdirectory has pathname
  432. X.I /pisa
  433. Xfrom a login on vanuata and
  434. X.I /vanuata.pisa
  435. Xfrom a login on hawaii.  Hence the need for the
  436. X.B KSHDIRFILE
  437. Xvariable, to say which is the right cache file for the domain you're logged
  438. Xin to.  If you only ever use one domain you can ignore this.
  439. X
  440. X.SH SECTARIAN BRAG
  441. X
  442. XYou don't have a prayer of adapting these to the antediluvian C or Bourne
  443. Xshells while still getting useful speed.
  444. X
  445. X.SH AUTHOR
  446. X
  447. XJack Campin, Glasgow University Computing Science Department, 17 Lilybank
  448. XGardens, Glasgow G12 8QQ, Scotland (jack@cs.glasgow.ac.uk)
  449. ________This_Is_The_END________
  450. if test `wc -c < kashe.1` -ne 9439; then
  451.     echo 'shar: kashe.1 was damaged during transit (should have been 9439 bytes)'
  452. fi
  453. fi        ; : end of overwriting check
  454. echo 'x - .kshenv'
  455. if test -f .kshenv; then echo 'shar: not overwriting .kshenv'; else
  456. sed 's/^X//' << '________This_Is_The_END________' > .kshenv
  457. X# ".kshenv" (or rename to whatever ENV is set to).
  458. X
  459. X# An assortment of functions for moving around the file
  460. X# system with fewer keystrokes, using a menu interface.
  461. X
  462. X# Jack Campin, 1988
  463. X
  464. X##  u             - up
  465. X##  d [directory] - down [from "directory"]
  466. X##  c [directory] - cd to a cached (or new) directory by menu,
  467. X##                  or add "directory" to the cache and cd to it
  468. X##  g number      - cd to a cached directory by number rather than menu
  469. X##  p pattern     - cd to a cached directory containing "pattern"
  470. X##  csort           - sort directory cache, removing duplicate entries
  471. X##  cdrop           - remove entries from cache; enter number(s) when prompted
  472. X##  cwipe [pattern] - empty the cache, or remove the items matching "pattern"
  473. X##  csave [file]    - write cache to a file, default $KSHDIRFILE or .kshenvdirs
  474. X##  cload [file]    - read cache from a file, default $KSHDIRFILE or .kshenvdirs
  475. X##  cgrep pattern   - cd to a menu-given directory below the current directory
  476. X##                    whose last component contains "pattern", adding all such
  477. X##                    directories to the cache
  478. X##  chelp           - print this synopsis
  479. X
  480. X# These use a cache of newline-separated directories in a variable KSHENVDIRS.
  481. X
  482. Xalias -t awk cat egrep lc ls sed sort tr  # speeds things up a bit
  483. X
  484. XNL="
  485. X"  export NL    # newline, used for IFS; variable used for readability
  486. X
  487. Xfunction c {
  488. X    typeset ifs="$IFS"  ps3="$PS3"
  489. X    trap 'IFS="$ifs" ;  PS3="$ps3"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  490. X    typeset j  i  val=1  ;  IFS="$NL"
  491. X    if    [ $# != 0 ]
  492. X    then    j=$1
  493. X    else    if    [ "$KSHENVDIRS" != "" ]
  494. X        then    PS3="number? "
  495. X            select i in $KSHENVDIRS New...
  496. X            do    [ "$i" = "New..." ]        &&  break
  497. X                test -n "$i"  &&   cd $i   ||  continue
  498. X                IFS="$ifs"  ;  PS3="$ps3"  ;   return 0
  499. X            done
  500. X        fi
  501. X        read j?"directory? "
  502. X    fi
  503. X    if    [ "$j" != "" ]    # not interrupted while reading
  504. X    then    if    eval cd $j    # makes tilde substitution work
  505. X        then    # avoid introducing a duplicate
  506. X            typeset x="$PWD"
  507. X            for i in $KSHENVDIRS
  508. X            do    [ "$x" = "$i" ]  &&  x=""  &&  break
  509. X            done
  510. X            KSHENVDIRS="$KSHENVDIRS$x$NL"  export KSHENVDIRS
  511. X            val=0
  512. X        fi
  513. X    fi
  514. X    IFS="$ifs"  ;  PS3="$ps3"  ;  return $val
  515. X}
  516. X
  517. Xfunction g {
  518. X    typeset ifs="$IFS"
  519. X    trap 'IFS="$ifs"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  520. X    IFS="$NL"
  521. X    if    [ $# != 1 ]
  522. X    then    print "Usage: g <number>" 1>&2
  523. X    else    typeset -i n=0  ;  typeset j
  524. X        for j in $KSHENVDIRS
  525. X        do    (( n = $n + 1 ))
  526. X            [ $n = $1 ]  ||  continue
  527. X            cd $j  &&  IFS="$ifs"  &&  return 0
  528. X            IFS="$ifs"  ;  return 1
  529. X        done
  530. X        print "g: no directory number $1" 1>&2
  531. X    fi
  532. X    IFS="$ifs"  ;  return 1
  533. X}
  534. X
  535. Xfunction p {
  536. X    [ $# != 1 ]    &&  print "Usage: p pattern" 1>&2  &&  return 1
  537. X    [ "$1" = "" ]  &&  print "p: null argument" 1>&2  &&  return 1
  538. X    typeset ifs="$IFS"  ps3=$PS3
  539. X    trap 'IFS="$ifs"  ;  PS3="$ps3"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  540. X    typeset i val=1 dirs="`print "$KSHENVDIRS" | egrep "$1"`"  ;  IFS="$NL"
  541. X    if    [ "$dirs" = "" ]
  542. X    then    print "p: no match found for '""$1""'" 1>&2
  543. X    else    set $dirs
  544. X        if    [ ${#*} = 1 ]
  545. X        then    cd $dirs  ;  val=0
  546. X        else    PS3="number? "
  547. X            select i in $dirs
  548. X            do    cd $i  &&  val=0  &&  break
  549. X            done
  550. X        fi
  551. X    fi
  552. X    IFS="$ifs"  ;  PS3=$ps3
  553. X    return $val
  554. X}
  555. X
  556. Xfunction csort {
  557. X    typeset ifs="$IFS"
  558. X    trap 'IFS=" "  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  559. X    IFS="$NL"
  560. X    KSHENVDIRS=`print "$KSHENVDIRS" | sort -u`$NL   export KSHENVDIRS
  561. X    IFS="$ifs"
  562. X}
  563. X
  564. Xfunction cdrop {
  565. X    [ "$KSHENVDIRS" = "" ]   &&  print "cdrop: nothing to drop" 1>&2  &&  return 0
  566. X    typeset ifs="$IFS"  ps3="$PS3"  i
  567. X    trap 'IFS="$ifs"  ;  PS3="$ps3"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  568. X    PS3="numbers to drop? "  ;  IFS="$NL"
  569. X    select i in $KSHENVDIRS
  570. X    do    typeset -i m=0  ;  typeset y="$KSHENVDIRS"
  571. X        for m in `print $REPLY | tr ' \011' '\012'`  # sidestep IFS
  572. X        do    typeset x=""  ;  typeset j  ;  typeset -i n=0
  573. X            for j in $y
  574. X            do    (( n = $n + 1 ))
  575. X                if    [ $m = $n ]
  576. X                then    x="$x@$NL"    # tombstone value
  577. X                else    x="$x$j$NL"
  578. X                fi
  579. X            done
  580. X            y="$x"
  581. X        done
  582. X        typeset tmp=""
  583. X        for i in $y    # edit out the tombstones
  584. X        do    [ $i != "@" ]  &&  tmp="$tmp$i$NL"
  585. X        done
  586. X        KSHENVDIRS="$tmp"  export KSHENVDIRS
  587. X        IFS="$ifs"  ;  PS3="$ps3"  ;  break
  588. X    done
  589. X}
  590. X
  591. Xfunction csave {
  592. X    typeset x
  593. X    case $# in
  594. X    0)    if    [ "$KSHDIRFILE" != "" ]
  595. X        then    x=$KSHDIRFILE
  596. X        else    x=~/.kshenvdirs
  597. X        fi  ;;
  598. X    1)    x=$1  ;;
  599. X    *)    print "Usage: csave [filename]" 1>&2  ;  return 1  ;;
  600. X    esac
  601. X    print "$KSHENVDIRS" > $x
  602. X}
  603. X
  604. Xfunction cload {
  605. X    typeset x
  606. X    case $# in
  607. X    0)    if    [ "$KSHDIRFILE" != "" ]
  608. X        then    x=$KSHDIRFILE
  609. X        else    x=~/.kshenvdirs
  610. X        fi  ;;
  611. X    1)    x=$1  ;;
  612. X    *)    print "Usage: cload [filename]" 1>&2  ;  return 1  ;;
  613. X    esac
  614. X    if    test -r $x
  615. X    then    typeset i  here="$PWD"  tmp="$KSHENVDIRS"  ifs="$IFS"
  616. X        trap 'IFS="$ifs"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  617. X        IFS="$NL"
  618. X        for i in `cat $x`
  619. X        do    cd "$i"  &&  tmp="$tmp$i$NL"
  620. X            cd "$here"
  621. X        done
  622. X        KSHENVDIRS="$tmp"  export KSHENVDIRS
  623. X    else    print "cload: $x unreadable" 1>&2  ;  IFS="$ifs"  ;  return 1
  624. X    fi
  625. X    IFS="$ifs"
  626. X}
  627. X
  628. Xfunction cwipe {
  629. X    case $# in
  630. X    0)    KSHENVDIRS="" export KSHENVDIRS  ;  return 0   ;;
  631. X    1)    typeset ifs="$IFS"  ;  IFS="$NL"
  632. X        trap 'IFS="$ifs"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  633. X        typeset i  j  y="$KSHENVDIRS"  tmp=""
  634. X        for j in `print "$KSHENVDIRS" | egrep $1`
  635. X        do    typeset x=""
  636. X            for i in $y
  637. X            do    if    [ "$i" = "$j" ]
  638. X                then    x="$x@$NL"
  639. X                else    x="$x$i$NL"
  640. X                fi
  641. X            done
  642. X            y="$x"
  643. X        done
  644. X        for i in $y    # edit out tombstones
  645. X        do    [ "$i" = "@" ]  ||  tmp="$tmp$i$NL"
  646. X        done
  647. X        KSHENVDIRS="$tmp" export KSHENVDIRS
  648. X        IFS="$ifs"  ;;
  649. X    *)    print "Usage: cwipe [pattern]" 1>&2  ;  return 1  ;;
  650. X    esac
  651. X}
  652. X
  653. Xfunction cgrep {
  654. X    typeset ifs="$IFS"  ps3="$PS3"
  655. X    trap 'IFS="$ifs"  ;  PS3="$ps3"  ;  return 1'  1 2 3 4 5 6 7 8 14 15
  656. X    if    [ $# != 1 ]
  657. X    then    print "Usage: cgrep pattern" 1>&2  ;  return 1
  658. X    fi
  659. X    typeset x="`ls -R        |
  660. X        sed -n '/:$/s/://p'    |
  661. X        egrep '(.*/)*.*'"${1}"'.*([~/])*$'`"
  662. X    typeset i  y=""  here="$PWD"  ;  PS3="number? "  IFS="$NL"
  663. X    for i in $x
  664. X    do    cd $i  &&  y="$y$PWD$NL"  &&  cd $here
  665. X    done
  666. X    KSHENVDIRS="$KSHENVDIRS$y"  export KSHENVDIRS
  667. X    select i in $KSHENVDIRS
  668. X    do    cd $i  &&  break
  669. X    done
  670. X    IFS="$ifs"  ;  PS3=$ps3
  671. X}
  672. X
  673. Xfunction u {
  674. X    cd ..
  675. X}
  676. X
  677. Xfunction d {
  678. X    typeset ifs="$IFS"  ps3="$PS3"  tmp="$PWD"  val=1  i
  679. X    trap 'IFS="$ifs" ; PS3="$ps3" ; cd "$tmp" ; return 1' 1 2 3 4 5 6 7 8 14 15
  680. X    case $# in
  681. X    0)    ;;
  682. X    1)    cd "$1"  ||  return 1  ;;    # test if target is a directory
  683. X    *)    print "Usage: d [directory]" 1>&2  ;  return 1  ;;
  684. X    esac
  685. X    PS3="number? "  ;  IFS="$NL"
  686. X    select i in `lc -d1`
  687. X# slower alternative if "lc" is not available
  688. X# the gross pattern is (empirically) faster than the obvious one
  689. X#    select i in `ls -al |
  690. X#        sed -n '/^d.*/{
  691. X#            s/[^ ]*[ ]*//
  692. X#            s/[^ ]*[ ]*//
  693. X#            s/[^ ]*[ ]*//
  694. X#            s/[^ ]*[ ]*//
  695. X#            s/[^ ]*[ ]*//
  696. X#            s/[^ ]*[ ]*//
  697. X#            s/[^ ]*[ ]*//
  698. X#            s/^\.*$//
  699. X#            p
  700. X#            }'`
  701. X    do    [ "$i" != "" ]  &&  cd $i  &&  val=0  &&  break
  702. X    done
  703. X    IFS="$ifs"  ;  PS3=$ps3  ;  return $val
  704. X}
  705. X
  706. Xfunction chelp {
  707. X    sed -n '/^##/s/^##//p' < $ENV
  708. X}
  709. ________This_Is_The_END________
  710. if test `wc -c < .kshenv` -ne 6819; then
  711.     echo 'shar: .kshenv was damaged during transit (should have been 6819 bytes)'
  712. fi
  713. fi        ; : end of overwriting check
  714. exit 0
  715.  
  716.  
  717.