daniel@island.COM (Dan Smith) (04/19/91)
Submitted by: daniel@island.com Archive-name: Directory Travel Aliases/part01 Directory/Travel aliases for csh, version 1.0 for net.consumption Daniel Smith, daniel@island.com, April 1991 A while back I mentioned I would post my aliases, I'm finally getting to it. It's been that kind of year :-) These aliases grow out of having used csh over the last 8 years or so. I promised I would send them to someone who had written me, but I've lost his email. I figure others may be interested, hence the post. I like to push and pop directories a lot, and I use the idea of creating an alias to source a csh script fragment a lot. Hope this is useful to some of you out there. Let me know of any improvements you may have. Move the ALIASES file to some name you like, and have your .cshrc file source it. A couple of the external scripts want to have grabchars handy. If you do not have this program, contact me (or any well-kept comp.sources.misc archive), and I'll send it to you. If anyone has trouble with this becuase of lines being longer than 80 characters, please let me know, and I will mail you a uuencoded version of this shar. Daniel ---- Cut Here and unpack ---- #!/bin/sh # This is Directory Travel Aliases, a shell archive (shar 3.10) # made 04/19/1991 03:41 UTC by daniel@bermuda # Source directory /usr/bermuda/people/daniel/lib/travel # # existing files will NOT be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 1087 -rw-r--r-- README # 3423 -rwxr-xr-x ALIASES # 467 -rwxr-xr-x cdg_script # 351 -rwxr-xr-x cdp_script # 936 -rwxr-xr-x d_csh # 76 -rwxr-xr-x long_prompt # 221 -rwxr-xr-x p_csh # 66 -rwxr-xr-x popall_csh # 432 -rwxr-xr-x ptree # 444 -rwxr-xr-x sample_localrc # 111 -rwxr-xr-x short_prompt # 444 -rwxr-xr-x tg_csh # touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$ if [ -s /tmp/s3_touch$$ ] then TOUCH=can else TOUCH=cannot fi rm -f /tmp/s3_touch$$ # ============= README ============== if test -f README; then echo "File README exists"; else echo "x - extracting README (Text)" sed 's/^X//' << 'irtravel' > README && X XDirectory/Travel aliases for csh, version 1.0 for net.consumption X X Daniel Smith, daniel@island.com, April 1991 X X A while back I mentioned I would post my aliases, I'm finally Xgetting to it. It's been that kind of year :-) X X These aliases grow out of having used csh over the last 8 Xyears or so. I promised I would send them to someone who had written Xme, but I've lost his email. I figure others may be interested, hence Xthe post. X X I like to push and pop directories a lot, and I use the idea Xof creating an alias to source a csh script fragment a lot. Hope this Xis useful to some of you out there. Let me know of any improvements Xyou may have. X X Move the ALIASES file to some name you like, and have your X.cshrc file source it. X X A couple of the external scripts want to have grabchars handy. XIf you do not have this program, contact me (or any well-kept comp.sources.misc Xarchive), and I'll send it to you. X X If anyone has trouble with this becuase of lines being longer Xthan 80 characters, please let me know, and I will mail you a Xuuencoded version of this shar. X X Daniel irtravel chmod 0644 README || echo "restore of README fails" if [ $TOUCH = can ] then touch -am 0418203491 README fi fi # ============= ALIASES ============== if test -f ALIASES; then echo "File ALIASES exists"; else echo "x - extracting ALIASES (Text)" sed 's/^X//' << 'irtravel' > ALIASES && X# cshrc.travel X# X# aliases for setting the prompt and getting around X# X# fillstr is a var used in prompt, contains "(level)" when dirs are pushed X X# version 1.0 for Net.Consumption X# Daniel Smith, daniel@island.com, 3/15/91 X Xset fillstr="" Xset dnum="" Xset end=":-)" Xset bin_dir=~/bin Xset lib_dir=~/lib X X# the ~/.travel file should be trimmed regularly, it's used by "tg" Xtouch ~/.travel Xalias record_dir '(echo "\!* $cwd" >> ~/.travel &)' X X# my standard prompt Xalias prompt_set 'set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "' X X# set $old so we can bounce back and forth, update prompt X# if there is a .localrc, source it... Xalias cd 'set old=$cwd; chdir \!*; record_dir cd; prompt_set; if -e .localrc source .localrc' Xalias cdl 'cd \!*; /bin/ls' X X# run a command elsewhere in the filename space and come right back Xalias ce 'p \!:1 ; \!:2-$ ; pp' X X# this will let you do things like "...cdp us loca bi" for /usr/local/bin X# (cdp - full path, cdg - cd by grep) Xalias cdp 'set cd_attempt=(\!*); source $bin_dir/cdp_script' X X# like the above, but search starts at $cwd Xalias cdg 'set cd_attempt=(\!*); source $bin_dir/cdg_script' X Xalias b 'set back=$old; cd $back; pwd' Xalias bl 'b; ls' Xalias c. 'cdl ..' Xalias c.. 'cdl ../..' X X# hey! go to the directory that was last on the last command line... Xalias cl 'cd \!-1:$' X X# without args, will show dirstack. with args, greps dirstack X# this requires grabchars, and gives an easy means of hopping around X# the directory stack Xalias d 'set cd_attempt=(\!*); source $bin_dir/d_csh' X X X# used by push and pop aliases Xalias dir_number 'set fillstr; set dnum=`dirs`; shift dnum; if ($#dnum >= 1) set fillstr=" ($#dnum)"' X X# push and pop with informative prompt handling :-) Xalias p 'set cd_attempt=(\!*); source $bin_dir/p_csh' Xalias pp 'set o2=$cwd; popd; set old=$o2; dir_number; record_dir pp; prompt_set' X X# push all of the current subdirs seen by "*/" Xalias pa 'set cd_attempt=($cwd/*/); source $bin_dir/p_csh' X X# push and ls, arg is optional Xalias pl 'p \!*; l' X X# hey! push the dir we were just at Xalias po 'p $old' X X# pop and ls Xalias ppl 'pp; l' X Xalias slp source $lib_dir/long_prompt Xalias ssp source $lib_dir/short_prompt X X# change by directory? I forget now what cbd means, but the script is X# fun so check it out Xalias cbd 'source $bin_dir/cd_csh' X X# PAGER, as in "less" or "more"...review your tracks... Xalias tt '$PAGER ~/.travel' X X# okay, this is why we have the ~/.travel file, so we can come back to X# it with this alias and get to a directory that we only "sort of" X# remember the name to... Xalias tg 'set cd_attempt=(\!*); source $bin_dir/tg_csh' X Xalias .. cd .. Xalias ... cd ../.. X X# beware, this is powerful. What this does is push *every* directory X# in a subtree..good for those cleanup runs... Xalias fed 'source $bin_dir/ptree' X X# ...and to get back out in a hurry Xalias popall 'source $bin_dir/popall_csh' X X# I use this a lot, seems to be a common sequence... Xalias newdir 'mkdir \!* && cd \!* && pwd' X X X# push a directory, find the file you want, then copy it back to where you X# came from... when you popd, the copy will be there... X Xalias cpb 'set bdir=`dirs`; /bin/cp -i \!* $bdir[2]' Xalias mvb 'set bdir=`dirs`; /bin/mv -i \!* $bdir[2]' Xalias lnb 'set bdir=`dirs`; ln -s $cwd/\!* $bdir[2]; echo $bdir[2]/\!*' Xalias lsb 'set bdir=`dirs`; echo "in $bdir[2]..."; /bin/ls -F $bdir[2]/\!* | pr -l20 -4 | $PAGER' irtravel chmod 0755 ALIASES || echo "restore of ALIASES fails" if [ $TOUCH = can ] then touch -am 0418202791 ALIASES fi fi # ============= cdg_script ============== if test -f cdg_script; then echo "File cdg_script exists"; else echo "x - extracting cdg_script (Text)" sed 's/^X//' << 'irtravel' > cdg_script && X#!/bin/echo sorry,try:source Xset cd_str=($cd_attempt) Xset starting_point=$cwd Xset slash="/" Xif ( "$cd_str[1]" == "$slash" ) then X chdir / X shift cd_str Xendif Xwhile ($#cd_str) X if ($#cd_str > 1) then X cd *$cd_str[1]*/ >& /dev/null && echo cd to \"$cwd\"... && set success X else X set parent_point=$cwd X chdir $starting_point X p $parent_point/*$cd_str[1]*/ && echo pushed \"$cwd\"... X endif X shift cd_str Xend Xcd . X# X# cdg script, August 10, 1989 by island!daniel X# irtravel chmod 0755 cdg_script || echo "restore of cdg_script fails" if [ $TOUCH = can ] then touch -am 0418202791 cdg_script fi fi # ============= cdp_script ============== if test -f cdp_script; then echo "File cdp_script exists"; else echo "x - extracting cdp_script (Text)" sed 's/^X//' << 'irtravel' > cdp_script && Xset cdstr="" Xwhile ($#cd_attempt) X set cdstr="$cdstr/*$cd_attempt[1]*" X shift cd_attempt X echo $cdstr/ && cd $cdstr/ Xend X# X# cdp script, July 12, by unicom!daniel X# X# for full path expansion...make an alias that sets the X# variable $cd_attempt, and source this script like this: X# X# alias cdp 'set cd_attempt=(\!*); source /usr/public/bin/cdp_script' irtravel chmod 0755 cdp_script || echo "restore of cdp_script fails" if [ $TOUCH = can ] then touch -am 0418202791 cdp_script fi fi # ============= d_csh ============== if test -f d_csh; then echo "File d_csh exists"; else echo "x - extracting d_csh (Text)" sed 's/^X//' << 'irtravel' > d_csh && Xif ($#cd_attempt >= 1) then X set cd_str X while ($#cd_attempt) X set cd_str="${cd_str}.*${cd_attempt[1]}.*" X shift cd_attempt X end X set our_dirs=`echo $dnum | tr " " "\012" | grep "$cd_str"` X echo $our_dirs | tr " " "\012" | cat -n X if ($#our_dirs == 1) then X echo going to $our_dirs... X set cd_me=`echo $dnum | tr " " "\012" | cat -n | grep "$cd_str" | awk ' { print $1 }'` X p +${cd_me} X goto all_done X endif X set cd_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '` X echo "" X if ($cd_me =~ 0) then X p `grabchars -t 10 -d none -b -r -n 80 -q 'which dir? '` X else if ($cd_me !~ none) then X cd $our_dirs[$cd_me] X endif Xelse X echo $dnum | tr " " "\012" | cat -n X set push_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '` X echo "" X if ($push_me =~ 0) then X p `grabchars -t 10 -d none -b -r -n 80 -q 'which dir? '` X else if ($push_me !~ none) then X p +${push_me} X endif Xendif X Xall_done: irtravel chmod 0755 d_csh || echo "restore of d_csh fails" if [ $TOUCH = can ] then touch -am 0418202791 d_csh fi fi # ============= long_prompt ============== if test -f long_prompt; then echo "File long_prompt exists"; else echo "x - extracting long_prompt (Text)" sed 's/^X//' << 'irtravel' > long_prompt && Xalias prompt_set 'set prompt="\! $HOST"":${cwd}$fillstr $end "' Xprompt_set irtravel chmod 0755 long_prompt || echo "restore of long_prompt fails" if [ $TOUCH = can ] then touch -am 0418202791 long_prompt fi fi # ============= p_csh ============== if test -f p_csh; then echo "File p_csh exists"; else echo "x - extracting p_csh (Text)" sed 's/^X//' << 'irtravel' > p_csh && X#!/bin/echo sorry,try:source Xif ($#cd_attempt == 0) set cd_attempt="" Xwhile ($#cd_attempt) X set o2=$cwd X pushd $cd_attempt[1] > /dev/null X echo $cwd X set old=$o2 X dir_number X record_dir p X shift cd_attempt Xend Xprompt_set irtravel chmod 0755 p_csh || echo "restore of p_csh fails" if [ $TOUCH = can ] then touch -am 0418202791 p_csh fi fi # ============= popall_csh ============== if test -f popall_csh; then echo "File popall_csh exists"; else echo "x - extracting popall_csh (Text)" sed 's/^X//' << 'irtravel' > popall_csh && X@ looptimes=$#dnum Xwhile ( $looptimes > 0) X pp X @ looptimes-- Xend irtravel chmod 0755 popall_csh || echo "restore of popall_csh fails" if [ $TOUCH = can ] then touch -am 0418202791 popall_csh fi fi # ============= ptree ============== if test -f ptree; then echo "File ptree exists"; else echo "x - extracting ptree (Text)" sed 's/^X//' << 'irtravel' > ptree && Xecho looking at directories to push... Xset savecdpath=($cdpath) Xset right_here=`pwd` # $cwd sometimes freaks out here... Xset cdpath=( . .. ../.. ../../.. ../../../../..) Xset dirs_to_push=`find $right_here -type d -print | tee /dev/tty` Xif ($#dirs_to_push) then X shift dirs_to_push # get rid of current directory X while ($#dirs_to_push) X p $dirs_to_push[1] X shift dirs_to_push X end Xendif Xset cdpath=($savecdpath) Xunset savecdpath irtravel chmod 0755 ptree || echo "restore of ptree fails" if [ $TOUCH = can ] then touch -am 0418202791 ptree fi fi # ============= sample_localrc ============== if test -f sample_localrc; then echo "File sample_localrc exists"; else echo "x - extracting sample_localrc (Text)" sed 's/^X//' << 'irtravel' > sample_localrc && X# X# this is a sample ~/.localrc X# X# the idea for this particular one is that when you cd to a directory X# full of sound files, some handy aliases are set up for you. You X# can make anything you want to have happen fire off just by cd'ing X# to a directory... X@ Xset verbose Xalias play 'cat \!* > /dev/audio' Xalias hrm 'hrm -f \!:1 \!:2-$ > /dev/audio' Xalias exp 'exp -f \!:1 \!:2-$ > /dev/audio' Xalias rrev 'rrev \!* > /dev/audio' Xunset verbose irtravel chmod 0755 sample_localrc || echo "restore of sample_localrc fails" if [ $TOUCH = can ] then touch -am 0418203191 sample_localrc fi fi # ============= short_prompt ============== if test -f short_prompt; then echo "File short_prompt exists"; else echo "x - extracting short_prompt (Text)" sed 's/^X//' << 'irtravel' > short_prompt && Xalias prompt_set 'set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "' Xprompt_set irtravel chmod 0755 short_prompt || echo "restore of short_prompt fails" if [ $TOUCH = can ] then touch -am 0418202791 short_prompt fi fi # ============= tg_csh ============== if test -f tg_csh; then echo "File tg_csh exists"; else echo "x - extracting tg_csh (Text)" sed 's/^X//' << 'irtravel' > tg_csh && X@ num_lines=`grep $cd_attempt ~/.travel | head -20 | awk ' { print $2 } ' | sort -u | cat -n | tee ~/.cd_attempt | tee /dev/tty | wc -l` Xif ($num_lines < 10) then X set push_me=`grabchars -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '` Xelse X set push_me=`grabchars -n 2 -t 10 -d none -b -r -c'[0-9]' -q 'which one to go to? '` Xendif Xecho "" Xif ($push_me !~ none) then X p `sed -n ${push_me}p ~/.cd_attempt | awk ' { print $2 }'` Xendif irtravel chmod 0755 tg_csh || echo "restore of tg_csh fails" if [ $TOUCH = can ] then touch -am 0418202791 tg_csh fi fi exit 0 -- daniel@island.com Daniel Smith, Island Graphics, (415) 491 0765 x 250(w) daniel@world.std.com 4000 CivicCenterDrive SanRafael MarinCounty CA 94903 dansmith@well.sf.ca.us Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG! falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles