home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3225 < prev    next >
Encoding:
Internet Message Format  |  1991-04-21  |  14.2 KB

  1. From: daniel@island.COM (Dan Smith)
  2. Newsgroups: alt.sources
  3. Subject: Directory Travel Aliases/part01
  4. Message-ID: <3941@island.COM>
  5. Date: 19 Apr 91 03:48:15 GMT
  6.  
  7.  
  8. Submitted by: daniel@island.com
  9. Archive-name: Directory Travel Aliases/part01
  10.  
  11. Directory/Travel aliases for csh, version 1.0 for net.consumption
  12.  
  13.     Daniel Smith, daniel@island.com, April 1991
  14.  
  15.     A while back I mentioned I would post my aliases, I'm finally
  16. getting to it.  It's been that kind of year :-)
  17.  
  18.     These aliases grow out of having used csh over the last 8
  19. years or so.  I promised I would send them to someone who had written
  20. me, but I've lost his email.  I figure others may be interested, hence
  21. the post.
  22.  
  23.     I like to push and pop directories a lot, and I use the idea
  24. of creating an alias to source a csh script fragment a lot.  Hope this
  25. is useful to some of you out there.  Let me know of any improvements
  26. you may have.
  27.  
  28.     Move the ALIASES file to some name you like, and have your
  29. .cshrc file source it.
  30.  
  31.     A couple of the external scripts want to have grabchars handy.
  32. If you do not have this program, contact me (or any well-kept comp.sources.misc
  33. archive), and I'll send it to you.
  34.  
  35.     If anyone has trouble with this becuase of lines being longer
  36. than 80 characters, please let me know, and I will mail you a
  37. uuencoded version of this shar.
  38.  
  39.                 Daniel
  40.  
  41.  
  42. ---- Cut Here and unpack ----
  43. #!/bin/sh
  44. # This is Directory Travel Aliases, a shell archive (shar 3.10)
  45. # made 04/19/1991 03:41 UTC by daniel@bermuda
  46. # Source directory /usr/bermuda/people/daniel/lib/travel
  47. #
  48. # existing files will NOT be overwritten
  49. #
  50. # This shar contains:
  51. # length  mode       name
  52. # ------ ---------- ------------------------------------------
  53. #   1087 -rw-r--r-- README
  54. #   3423 -rwxr-xr-x ALIASES
  55. #    467 -rwxr-xr-x cdg_script
  56. #    351 -rwxr-xr-x cdp_script
  57. #    936 -rwxr-xr-x d_csh
  58. #     76 -rwxr-xr-x long_prompt
  59. #    221 -rwxr-xr-x p_csh
  60. #     66 -rwxr-xr-x popall_csh
  61. #    432 -rwxr-xr-x ptree
  62. #    444 -rwxr-xr-x sample_localrc
  63. #    111 -rwxr-xr-x short_prompt
  64. #    444 -rwxr-xr-x tg_csh
  65. #
  66. touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
  67. if [ -s /tmp/s3_touch$$ ]
  68. then
  69.     TOUCH=can
  70. else
  71.     TOUCH=cannot
  72. fi
  73. rm -f /tmp/s3_touch$$
  74. # ============= README ==============
  75. if test -f README; then echo "File README exists"; else
  76. echo "x - extracting README (Text)"
  77. sed 's/^X//' << 'irtravel' > README &&
  78. X
  79. XDirectory/Travel aliases for csh, version 1.0 for net.consumption
  80. X
  81. X    Daniel Smith, daniel@island.com, April 1991
  82. X
  83. X    A while back I mentioned I would post my aliases, I'm finally
  84. Xgetting to it.  It's been that kind of year :-)
  85. X
  86. X    These aliases grow out of having used csh over the last 8
  87. Xyears or so.  I promised I would send them to someone who had written
  88. Xme, but I've lost his email.  I figure others may be interested, hence
  89. Xthe post.
  90. X
  91. X    I like to push and pop directories a lot, and I use the idea
  92. Xof creating an alias to source a csh script fragment a lot.  Hope this
  93. Xis useful to some of you out there.  Let me know of any improvements
  94. Xyou may have.
  95. X
  96. X    Move the ALIASES file to some name you like, and have your
  97. X.cshrc file source it.
  98. X
  99. X    A couple of the external scripts want to have grabchars handy.
  100. XIf you do not have this program, contact me (or any well-kept comp.sources.misc
  101. Xarchive), and I'll send it to you.
  102. X
  103. X    If anyone has trouble with this becuase of lines being longer
  104. Xthan 80 characters, please let me know, and I will mail you a
  105. Xuuencoded version of this shar.
  106. X
  107. X                Daniel
  108. irtravel
  109. chmod 0644 README || echo "restore of README fails"
  110. if [ $TOUCH = can ]
  111. then
  112.     touch -am 0418203491 README
  113. fi
  114. fi
  115. # ============= ALIASES ==============
  116. if test -f ALIASES; then echo "File ALIASES exists"; else
  117. echo "x - extracting ALIASES (Text)"
  118. sed 's/^X//' << 'irtravel' > ALIASES &&
  119. X#    cshrc.travel
  120. X#
  121. X#    aliases for setting the prompt and getting around
  122. X#
  123. X#    fillstr is a var used in prompt, contains "(level)" when dirs are pushed
  124. X
  125. X#    version 1.0 for Net.Consumption
  126. X#    Daniel Smith, daniel@island.com, 3/15/91
  127. X
  128. Xset fillstr=""
  129. Xset dnum=""
  130. Xset end=":-)"
  131. Xset bin_dir=~/bin
  132. Xset lib_dir=~/lib
  133. X
  134. X#    the ~/.travel file should be trimmed regularly, it's used by "tg"
  135. Xtouch ~/.travel
  136. Xalias    record_dir    '(echo "\!*    $cwd" >> ~/.travel &)'
  137. X
  138. X#    my standard prompt
  139. Xalias    prompt_set     'set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "'
  140. X
  141. X#    set $old so we can bounce back and forth, update prompt
  142. X#    if there is a .localrc, source it...
  143. Xalias    cd    'set old=$cwd; chdir \!*; record_dir cd; prompt_set; if -e .localrc  source .localrc'
  144. Xalias    cdl    'cd \!*; /bin/ls'         
  145. X
  146. X#    run a command elsewhere in the filename space and come right back
  147. Xalias    ce    'p \!:1 ; \!:2-$ ; pp'
  148. X
  149. X#    this will let you do things like "...cdp us loca bi" for /usr/local/bin
  150. X#    (cdp - full path, cdg - cd by grep)
  151. Xalias    cdp    'set cd_attempt=(\!*); source $bin_dir/cdp_script'
  152. X
  153. X#    like the above, but search starts at $cwd
  154. Xalias    cdg    'set cd_attempt=(\!*); source $bin_dir/cdg_script'
  155. X
  156. Xalias    b    'set back=$old; cd $back; pwd'
  157. Xalias    bl    'b; ls'
  158. Xalias    c.    'cdl ..'
  159. Xalias    c..    'cdl    ../..'
  160. X
  161. X#    hey! go to the directory that was last on the last command line...
  162. Xalias    cl    'cd \!-1:$'
  163. X
  164. X#    without args, will show dirstack.  with args, greps dirstack
  165. X#    this requires grabchars, and gives an easy means of hopping around
  166. X#    the directory stack
  167. Xalias    d    'set cd_attempt=(\!*); source $bin_dir/d_csh'
  168. X
  169. X
  170. X#    used by push and pop aliases
  171. Xalias    dir_number    'set fillstr; set dnum=`dirs`; shift dnum; if ($#dnum >= 1) set fillstr=" ($#dnum)"'
  172. X
  173. X#    push and pop with informative prompt handling :-)
  174. Xalias    p    'set cd_attempt=(\!*); source $bin_dir/p_csh'
  175. Xalias    pp    'set o2=$cwd; popd; set old=$o2; dir_number; record_dir pp; prompt_set'
  176. X
  177. X#    push all of the current subdirs seen by "*/"
  178. Xalias    pa    'set cd_attempt=($cwd/*/); source $bin_dir/p_csh'
  179. X
  180. X#    push and ls, arg is optional
  181. Xalias    pl    'p \!*; l'
  182. X
  183. X#    hey! push the dir we were just at
  184. Xalias    po    'p $old'
  185. X
  186. X#    pop and ls
  187. Xalias    ppl    'pp; l'
  188. X
  189. Xalias    slp    source $lib_dir/long_prompt
  190. Xalias    ssp    source $lib_dir/short_prompt
  191. X
  192. X#    change by directory?  I forget now what cbd means, but the script is
  193. X#    fun so check it out
  194. Xalias    cbd    'source $bin_dir/cd_csh'
  195. X
  196. X#    PAGER, as in "less" or "more"...review your tracks...
  197. Xalias    tt    '$PAGER ~/.travel'
  198. X
  199. X#    okay, this is why we have the ~/.travel file, so we can come back to
  200. X#    it with this alias and get to a directory that we only "sort of"
  201. X#    remember the name to...
  202. Xalias    tg    'set cd_attempt=(\!*); source $bin_dir/tg_csh'
  203. X
  204. Xalias    ..    cd ..
  205. Xalias    ...    cd ../..
  206. X
  207. X#    beware, this is powerful.  What this does is push *every* directory
  208. X#    in a subtree..good for those cleanup runs...
  209. Xalias    fed    'source $bin_dir/ptree'
  210. X
  211. X#    ...and to get back out in a hurry
  212. Xalias    popall    'source $bin_dir/popall_csh'
  213. X
  214. X#    I use this a lot, seems to be a common sequence...
  215. Xalias    newdir    'mkdir \!* && cd \!* && pwd'
  216. X
  217. X
  218. X# push a directory, find the file you want, then copy it back to where you
  219. X# came from... when you popd, the copy will be there...
  220. X
  221. Xalias    cpb    'set bdir=`dirs`; /bin/cp -i \!* $bdir[2]'
  222. Xalias    mvb    'set bdir=`dirs`; /bin/mv -i \!* $bdir[2]'
  223. Xalias    lnb    'set bdir=`dirs`; ln -s $cwd/\!* $bdir[2]; echo $bdir[2]/\!*'
  224. Xalias    lsb    'set bdir=`dirs`; echo "in $bdir[2]..."; /bin/ls -F $bdir[2]/\!* | pr -l20 -4 | $PAGER'
  225. irtravel
  226. chmod 0755 ALIASES || echo "restore of ALIASES fails"
  227. if [ $TOUCH = can ]
  228. then
  229.     touch -am 0418202791 ALIASES
  230. fi
  231. fi
  232. # ============= cdg_script ==============
  233. if test -f cdg_script; then echo "File cdg_script exists"; else
  234. echo "x - extracting cdg_script (Text)"
  235. sed 's/^X//' << 'irtravel' > cdg_script &&
  236. X#!/bin/echo sorry,try:source
  237. Xset cd_str=($cd_attempt)
  238. Xset starting_point=$cwd
  239. Xset slash="/"
  240. Xif ( "$cd_str[1]" == "$slash" ) then
  241. X    chdir /
  242. X    shift cd_str
  243. Xendif
  244. Xwhile ($#cd_str)
  245. X    if ($#cd_str > 1) then
  246. X        cd *$cd_str[1]*/ >& /dev/null && echo cd to \"$cwd\"...  && set success
  247. X    else
  248. X        set parent_point=$cwd
  249. X        chdir $starting_point
  250. X        p $parent_point/*$cd_str[1]*/ && echo pushed \"$cwd\"...
  251. X    endif
  252. X    shift cd_str
  253. Xend
  254. Xcd .
  255. X#
  256. X#    cdg script, August 10, 1989 by island!daniel
  257. X#
  258. irtravel
  259. chmod 0755 cdg_script || echo "restore of cdg_script fails"
  260. if [ $TOUCH = can ]
  261. then
  262.     touch -am 0418202791 cdg_script
  263. fi
  264. fi
  265. # ============= cdp_script ==============
  266. if test -f cdp_script; then echo "File cdp_script exists"; else
  267. echo "x - extracting cdp_script (Text)"
  268. sed 's/^X//' << 'irtravel' > cdp_script &&
  269. Xset cdstr=""
  270. Xwhile ($#cd_attempt)
  271. X    set cdstr="$cdstr/*$cd_attempt[1]*"
  272. X    shift cd_attempt
  273. X    echo $cdstr/ && cd $cdstr/
  274. Xend
  275. X#
  276. X#    cdp script, July 12, by unicom!daniel
  277. X#
  278. X#    for full path expansion...make an alias that sets the
  279. X#    variable $cd_attempt, and source this script like this:
  280. X#
  281. X#    alias cdp 'set cd_attempt=(\!*); source /usr/public/bin/cdp_script'
  282. irtravel
  283. chmod 0755 cdp_script || echo "restore of cdp_script fails"
  284. if [ $TOUCH = can ]
  285. then
  286.     touch -am 0418202791 cdp_script
  287. fi
  288. fi
  289. # ============= d_csh ==============
  290. if test -f d_csh; then echo "File d_csh exists"; else
  291. echo "x - extracting d_csh (Text)"
  292. sed 's/^X//' << 'irtravel' > d_csh &&
  293. Xif ($#cd_attempt >= 1) then
  294. X    set cd_str
  295. X    while ($#cd_attempt)
  296. X        set cd_str="${cd_str}.*${cd_attempt[1]}.*"
  297. X        shift cd_attempt
  298. X    end
  299. X    set our_dirs=`echo $dnum | tr " " "\012" | grep "$cd_str"`
  300. X    echo $our_dirs | tr " " "\012" | cat -n
  301. X    if ($#our_dirs == 1) then
  302. X        echo going to $our_dirs...
  303. X        set cd_me=`echo $dnum | tr " " "\012" | cat -n | grep "$cd_str" | awk ' { print $1 }'`
  304. X        p +${cd_me}
  305. X        goto all_done
  306. X    endif
  307. X    set cd_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '`
  308. X    echo ""
  309. X    if ($cd_me =~ 0) then
  310. X        p `grabchars -t 10 -d none -b -r -n 80 -q 'which dir? '`
  311. X    else if ($cd_me !~ none) then
  312. X            cd $our_dirs[$cd_me]
  313. X    endif
  314. Xelse
  315. X    echo $dnum | tr " " "\012" | cat -n
  316. X    set push_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '`
  317. X    echo ""
  318. X    if ($push_me =~ 0) then
  319. X        p `grabchars -t 10 -d none -b -r -n 80 -q 'which dir? '`
  320. X    else if ($push_me !~ none) then
  321. X            p +${push_me}
  322. X    endif
  323. Xendif
  324. X
  325. Xall_done:
  326. irtravel
  327. chmod 0755 d_csh || echo "restore of d_csh fails"
  328. if [ $TOUCH = can ]
  329. then
  330.     touch -am 0418202791 d_csh
  331. fi
  332. fi
  333. # ============= long_prompt ==============
  334. if test -f long_prompt; then echo "File long_prompt exists"; else
  335. echo "x - extracting long_prompt (Text)"
  336. sed 's/^X//' << 'irtravel' > long_prompt &&
  337. Xalias    prompt_set     'set prompt="\! $HOST"":${cwd}$fillstr $end "'
  338. Xprompt_set
  339. irtravel
  340. chmod 0755 long_prompt || echo "restore of long_prompt fails"
  341. if [ $TOUCH = can ]
  342. then
  343.     touch -am 0418202791 long_prompt
  344. fi
  345. fi
  346. # ============= p_csh ==============
  347. if test -f p_csh; then echo "File p_csh exists"; else
  348. echo "x - extracting p_csh (Text)"
  349. sed 's/^X//' << 'irtravel' > p_csh &&
  350. X#!/bin/echo sorry,try:source
  351. Xif ($#cd_attempt == 0) set cd_attempt=""
  352. Xwhile ($#cd_attempt)
  353. X    set o2=$cwd
  354. X    pushd $cd_attempt[1] > /dev/null
  355. X    echo $cwd
  356. X    set old=$o2
  357. X    dir_number
  358. X    record_dir p
  359. X    shift cd_attempt
  360. Xend
  361. Xprompt_set
  362. irtravel
  363. chmod 0755 p_csh || echo "restore of p_csh fails"
  364. if [ $TOUCH = can ]
  365. then
  366.     touch -am 0418202791 p_csh
  367. fi
  368. fi
  369. # ============= popall_csh ==============
  370. if test -f popall_csh; then echo "File popall_csh exists"; else
  371. echo "x - extracting popall_csh (Text)"
  372. sed 's/^X//' << 'irtravel' > popall_csh &&
  373. X@ looptimes=$#dnum
  374. Xwhile ( $looptimes > 0)
  375. X    pp
  376. X    @ looptimes--
  377. Xend
  378. irtravel
  379. chmod 0755 popall_csh || echo "restore of popall_csh fails"
  380. if [ $TOUCH = can ]
  381. then
  382.     touch -am 0418202791 popall_csh
  383. fi
  384. fi
  385. # ============= ptree ==============
  386. if test -f ptree; then echo "File ptree exists"; else
  387. echo "x - extracting ptree (Text)"
  388. sed 's/^X//' << 'irtravel' > ptree &&
  389. Xecho looking at directories to push...
  390. Xset savecdpath=($cdpath)
  391. Xset right_here=`pwd`    # $cwd sometimes freaks out here...
  392. Xset cdpath=( . .. ../.. ../../.. ../../../../..)
  393. Xset dirs_to_push=`find $right_here -type d -print | tee /dev/tty`
  394. Xif ($#dirs_to_push) then
  395. X    shift dirs_to_push        # get rid of current directory
  396. X    while ($#dirs_to_push)
  397. X        p $dirs_to_push[1]
  398. X        shift dirs_to_push
  399. X    end
  400. Xendif
  401. Xset cdpath=($savecdpath)
  402. Xunset savecdpath
  403. irtravel
  404. chmod 0755 ptree || echo "restore of ptree fails"
  405. if [ $TOUCH = can ]
  406. then
  407.     touch -am 0418202791 ptree
  408. fi
  409. fi
  410. # ============= sample_localrc ==============
  411. if test -f sample_localrc; then echo "File sample_localrc exists"; else
  412. echo "x - extracting sample_localrc (Text)"
  413. sed 's/^X//' << 'irtravel' > sample_localrc &&
  414. X#
  415. X#    this is a sample ~/.localrc
  416. X#
  417. X#    the idea for this particular one is that when you cd to a directory
  418. X#    full of sound files, some handy aliases are set up for you.  You
  419. X#    can make anything you want to have happen fire off just by cd'ing
  420. X#    to a directory...
  421. X@
  422. Xset verbose
  423. Xalias play 'cat \!* > /dev/audio'
  424. Xalias hrm 'hrm -f \!:1 \!:2-$ > /dev/audio'
  425. Xalias exp 'exp -f \!:1 \!:2-$ > /dev/audio'
  426. Xalias rrev 'rrev \!* > /dev/audio'
  427. Xunset verbose
  428. irtravel
  429. chmod 0755 sample_localrc || echo "restore of sample_localrc fails"
  430. if [ $TOUCH = can ]
  431. then
  432.     touch -am 0418203191 sample_localrc
  433. fi
  434. fi
  435. # ============= short_prompt ==============
  436. if test -f short_prompt; then echo "File short_prompt exists"; else
  437. echo "x - extracting short_prompt (Text)"
  438. sed 's/^X//' << 'irtravel' > short_prompt &&
  439. Xalias    prompt_set     'set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "'
  440. Xprompt_set
  441. irtravel
  442. chmod 0755 short_prompt || echo "restore of short_prompt fails"
  443. if [ $TOUCH = can ]
  444. then
  445.     touch -am 0418202791 short_prompt
  446. fi
  447. fi
  448. # ============= tg_csh ==============
  449. if test -f tg_csh; then echo "File tg_csh exists"; else
  450. echo "x - extracting tg_csh (Text)"
  451. sed 's/^X//' << 'irtravel' > tg_csh &&
  452. X@ num_lines=`grep $cd_attempt ~/.travel | head -20 | awk ' { print $2 } ' | sort -u | cat -n | tee ~/.cd_attempt | tee /dev/tty | wc -l`
  453. Xif ($num_lines < 10) then
  454. X    set push_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '`
  455. Xelse
  456. X    set push_me=`grabchars -n 2 -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '`
  457. Xendif
  458. Xecho ""
  459. Xif ($push_me !~ none) then
  460. X        p `sed -n ${push_me}p  ~/.cd_attempt | awk ' { print $2 }'`
  461. Xendif
  462. irtravel
  463. chmod 0755 tg_csh || echo "restore of tg_csh fails"
  464. if [ $TOUCH = can ]
  465. then
  466.     touch -am 0418202791 tg_csh
  467. fi
  468. fi
  469. exit 0
  470. -- 
  471. daniel@island.com       Daniel Smith, Island Graphics, (415) 491 0765 x 250(w)
  472. daniel@world.std.com      4000 CivicCenterDrive SanRafael MarinCounty CA 94903
  473. dansmith@well.sf.ca.us      Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG!
  474. falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles
  475.