home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
3
/
3dired11.zip
/
UNXDIRED.CMD
< prev
Wrap
OS/2 REXX Batch file
|
1992-08-22
|
27KB
|
872 lines
; This is version 1.1-Unix of Dired for MicroEMACS, enhanced and de-boned
; over the first DOS release. I've added a couple features and cleaned
; up the code. Thanks very much to Richard Meitzler for beta testing this
; 1.1 version. It's been tested on a Sparc station and an IBM RISC 6000.
;
; Version 1.1-Dos also exists for dired.cmd; the file is called dosdired.cmd
;
; Of course I'm happy to hear bug reports and feedback about this code
; so don't hesitate to write if something goes wrong (or even right).
; I'm at:
;
; hetrick@gauge.phys.uva.nl
; Theoretical Physics Institute
; University of Amsterdam, The Netherlands
;
; Salut,
; Jim Hetrick
;
;=====================================================================
;
; =====UnxDired.cmd=====
; version 1.1-Unix
;
; A Directory Facility for MicroEMACS 3.11 under Unix
;
; (C)opyright 1992 by James E. Hetrick
;
; Dired.cmd is modeled after GNUEmacs' Dired.el to some degree.
; It lists directories, allows you to manipulate files in them,
; and to move around your directory tree.
;
; ******* READ THIS ***** READ THIS ****** READ THIS ********
;
; As this program has the capability to DELETE YOUR
; FILES please put some test files in a subdirectory and try it
; out on them. After you're convinced of its integrity, put it
; wherever your .cmd files live and fire at will.
;
; ******* READ THIS ***** READ THIS ****** READ THIS ********
;
;
;
; ===============
; Documentation
; ===============
;
; To Load: either -> uncomment the Dired code page below and
; make the changes to your .emacsrc file
; or -> load with "execute-file unxdired.cmd"
;
; To Run: hit C-x d (^XD) or M-x D-open to start dired.
;
; (C-x d is remapped by Dired.cmd. If you need it,
; remap D-open to some other key).
;
; Dired prompts you for a directory. Either type an alternative
; directory or accept (by hitting <ENTER>) the default directory
; from which MicroEMACS was called.
;
; From here you can move UP and DOWN the files with the arrow keys.
; Tapping "f" loads the file into a buffer for editting replacing the
; Dired directory.
;
; If you hit "f" on a subdirectory, that subdir is loaded as
; a Dired buffer.
;
; In a Dired buffer there is a new META key, so to speak, "q" by
; default. Usually one tells Dired what to do by hitting letter keys
; "f", "o", "m", etc., as in it's GNU inspiration. Should you need
; to do something which is bound to a control sequence, like C-x k
; (delete-buffer) or C-x x (next-buffer), you first type "q", Dired will
; then prompt you with "Command sequence:". Here you enter a normal
; control sequence, and Dired will process it as best it can. Using
; "q" as the Dired-META key, avoids the difficulties that seem
; arise in using the function keys across a variety of different machines.
;
; Dired-buffers (Dired-C:\DIR\...) are like others and stay in the
; background while editing files or performing other tasks. If you
; "next-buffer" q-(C-x x) into a Dired directory buffer, Dired starts
; again and you have it's commands at your disposal. If you should
; find yourself back in a Dired-buffer which is not responding to
; Dired commands such as happens when you split the screen by "o"
; (view-file-other-window) or "t" (tar-view) on a .tar file, just
; type C-x C-d to restart the Dired command processor in the window.
;
; I prefer C-x k to delete the current buffer and replace
; with the next on the stack like GNUEmacs, so I have the
; macro "kill-this-one" bound to C-x k, in my .emacsrc.
; If you like it, do the same, and Dired will process it. Otherwise,
; you can comment out the !if..."kill-this-one" loop out (or leave it).
;
; ***************************************************************
;store-procedure kill-this-one
; set %thisone $cbufname
; set %ans @&cat &cat "Delete [" %thisone "]: "
; !if &seq %ans ""
; !force next-buffer
; !force delete-buffer %thisone
; !else
; !force delete-buffer %ans
; !endif
;!endm
;
;macro-to-key kill-this-one ^XK
; ****************************************************************
;
; Below is the list of Dired commands, executed singly when the cursor is
; on a file name and no files are marked (*ed), or executed on the
; *ed files en masse:
;
; Movement:
;
; arrow keys: up and down (seem to work for me)
; P, N: up, down respectively
; k, j: up, down respectively
; q-PgUpKey, V: Page-up
; q-PgDnKey, B: Page-down
;
; A note about movement keys: the V and B above are delivered on some
; machines as the ***key*** entered when hitting PgUp and PgDn. The
; ***cmd*** is still (previous/next-page). Hence, your PgUp/Dn keys
; may work just as keys, or you may have to prefix them with the
; Dired-META "q" ie. q-PgUp... Failing that you can just enter "V"
; or "B". The same applies to the arrow keys. Mine seem to work with
; P and N, however k and j (like vi) are supplied in case yours don't.
;
; (If you feel like recompiling, Richard Meitzler, Stratus Computer, Marlboro,
; MA, [rgm@hw.stratus.com] has had some success fixing unix.c in the memacs
; source to interpret the Sun/Sparc function keys.)
;
; Commands:
;
; f --- load file/directory into current window
;
; o --- load file/directory into another window
;
; m,d -- mark file (with %markstr)
;
; u --- unmark file
;
; c --- copy (marked) file(s)
;
; r --- rename or move (marked) file(s)
;
; x --- delete (marked) file(s) [you're prompted; prompting can be turned off]
;
; C --- compress ...
;
; U --- uncompress ...
;
; e --- extract tar file
;
; t --- on a .tar archive, view contents in other window
; --- or tar (marrked) file(s) into an archive
; (must be viewing directory from which MicroEMACS
; was invoked, ie. default directory at startup
; so that files in tar file are portable---with no paths)
;
; a --- execute file (useful for .cmd files; doesn't always work)
;
; z --- leave dired processor (Dired-buffer becomes like any other)
;
; Note that file or directory inputs to Dired are globbed
; so that ~/filename is expanded using you $HOME variable
; (only ~/ is expanded though).
;
; Filenames and directories entered for copy, move, etc., are processed
; as follows: a single name gets the currently viewed directory prepended
; to it. If the filename/dir is entered with "/"'s in it, it's assumed
; that it represents a full pathname and left alone. ".." is a valid
; directory and will be expanded relative to the viewed directory.
;
; C-x C-f (find-file) while in a some directory, opens a (new) file in that
; directory.
;
;
;========================== Dired ======================================
; Feel free to comment out this one:
write-message " -\|/- Dired <1.1-Unix> for MicroEMACS === 1992 (c) J. E. Hetrick >> C-x d"
set %marked 0
set %revert FALSE
set %dot FALSE
set %othwin FALSE
set %dirowin FALSE
set %comseq "q" ; for command sequnce input (see D-getcmd)
set %markstr " * " ; must be 3 chars
set %home &env "HOME" ; for globbing
; =======D-check
store-procedure D-check
!if &seq &left $cbufname 6 "Dired-"
set $discmd FALSE
set %length &len $cbufname
set %dir &rig $cbufname &sub %length 6
set %Dbuffer &cat "Dired-" %dir
change-file-name " "
beginning-of-file
set %starred FALSE
set %marked 0
!while &seq %starred FALSE
!force search-forward %markstr
!if &seq $status TRUE
set %marked &add %marked 1
!else
set %starred TRUE
!endif
!endwhile
unmark-buffer %Dbuffer
beginning-of-file
!force search-forward ".."
set %ncol &sub $curcol 2
next-line
beginning-of-line
!force %ncol forward-character
set %filename " "
set $discmd TRUE
D-process
!endif
!endm
; ==============D-open
store-procedure D-open
set $discmd FALSE
!if &seq %rcfkeys TRUE
!force toggle-fkeys
!endif
pipe-command "pwd"
beginning-of-file
set %cwd #command
set %dir @&cat &cat "Directory [" %cwd "]: "
!if &seq %dir "ERROR"
write-message "Aborting..."
delete-window
delete-buffer "command"
!return
!endif
delete-window
set $discmd TRUE
!if &sequal %dir ""
set %dir %cwd
!else
!if &seq &left %dir 2 "~~/"
set %dir &cat %home &right %dir &sub &len %dir 1
!endif
!endif
D-window
!endm
; =========D-window
store-procedure D-window
!if &seq %revert FALSE
write-message &cat &cat "[Reading " %dir "...]
!endif
pipe-command &cat "ls -al " %dir
!if &seq %othwin FALSE
delete-other-windows
!endif
set %othwin FALSE
!if &seq %dirowin TRUE
set %dirowin FALSE
save-window
next-window
delete-window
restore-window
!endif
!force delete-buffer "stale"
set %rcfkeys FALSE
delete-mode "View"
set %Dbuffer &cat "Dired-" %dir
name-buffer %Dbuffer
change-file-name " "
beginning-of-file
set-mark
end-of-file
set %tabno $hardtab
set $hardtab 3
indent-region
detab-region
set $hardtab %tabno
beginning-of-file
unmark-buffer %Dbuffer
!if &seq %revert TRUE
goto-line %oldline
set %revert FALSE
!else
!force search-forward ".."
set %ncol &sub $curcol 2
next-line
!endif
beginning-of-line
!force %ncol forward-character
set %filename " "
set $discmd TRUE
D-process
!endm
; ==============D-getcmd
store-procedure D-getcmd
!if &seq $pending FALSE
!force update-screen
!endif
set %cmd " "
set %key >key
!if &seq %key %comseq
write-message "Command sequence:"
set %cmd >cmd
set %cmd &bind %cmd
write-message %cmd
!endif
!endm
; ==============D-process
store-procedure D-process
write-message "Dired ON"
set $discmd FALSE
set %done FALSE
!while &seq %done FALSE
D-getcmd
;======Movement======
!if &or &or &seq %key "k" &seq %key "P" &seq %cmd "previous-line"
!force previous-line
beginning-of-line
!force %ncol forward-character
!goto endproc
!endif
!if &or &seq %key "B" &seq %cmd "previous-page"
!force previous-page
beginning-of-line
!force %ncol forward-character
!goto endproc
!endif
!if &or &or &seq %key "j" &seq %key "N" &seq %cmd "next-line"
!force next-line
beginning-of-line
!force %ncol forward-character
!goto endproc
!endif
!if &or &seq %key "V" &seq %cmd "next-page"
!force next-page
beginning-of-line
!force %ncol forward-character
!goto endproc
!endif
; ======Edit file====== ---"f"---
!if &or &seq %key "f" &seq %cmd "mouse-region-down"
D-getfile
D-load-file
!endif
; ======Edit file other window====== ---"o"---
!if &seq %key "o"
set %othwin TRUE
2 split-current-window
D-getfile
!if &seq %dirq "d"
set %dirowin TRUE
!endif
D-load-file
!endif
; ======Copy file======= ---"c"---
!if &seq %key "c"
D-getfile
!if &gre %marked 0
set %copy @"Copy marked files to: "
!if &seq %copy ".."
set %copy &cat %dir "/.."
!endif
!if &seq &left %copy 2 "~~/"
set %copy &cat %home &right %copy &sub &len %copy 1
!else
!if &equ &sind %copy "/" 0
set %copy &cat &cat %dir "/" %copy
!endif
!endif
set %count 0
!while &gre %marked 0
beginning-of-file
search-forward %markstr
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
D-getfile
shell-command &cat &cat &cat "cp " %filename " " %copy
set %count &add %count 1
!endwhile
write-message &cat %count " files copied"
!else
set %copy @&cat &cat "Copy " %shortfile " to: "
!if &seq %copy ".."
set %copy &cat %dir "/.."
!endif
!if &seq &left %copy 2 "~~/"
set %copy &cat %home &right %copy &sub &len %copy 1
!else
!if &equ &sind %copy "/" 0
set %copy &cat &cat %dir "/" %copy
!endif
!endif
shell-command &cat &cat &cat "cp " %filename " " %copy
!endif
D-revert
!break
!endif
; ======Delete file(s)== ---"x"---
!if &seq %key "x"
!if &gre %marked 0
set %count 0
!while &gre %marked 0
beginning-of-file
search-forward %markstr
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
D-getfile
; comment this set-if-loop out for no-prompt deletion of marked files
set %delq @&cat &cat "Delete " %filename "? [y/n]: "
!if &seq &low %delq "y"
D-delete
!endif
set %count &add %count 1
!endwhile
write-message &cat %count " files deleted"
!else
D-getfile
; comment this set-if-loop out for no-prompt deletion of file
set %delq @&cat &cat "Delete " %filename "? [y/n]: "
!if &seq &low %delq "y"
D-delete
!else
write-message "No files deleted"
!endif
!endif
beginning-of-line
!force %ncol forward-character
set %delq " "
!goto endproc
!endif
; ======Move file======= ---"r"---
!if &seq %key "r"
!if &gre %marked 0
set %move @"Move marked files to: "
!if &seq %move ".."
set %move &cat %dir "/.."
!endif
!if &seq &left %move 2 "~~/"
set %move &cat %home &right %move &sub &len %move 1
!else
!if &equ &sind %move "/" 0
set %move &cat &cat %dir "/" %move
!endif
!endif
set %count 0
!while &gre %marked 0
beginning-of-file
search-forward %markstr
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
D-getfile
shell-command &cat &cat &cat "mv -i " %filename " " %move
set %count &add %count 1
!endwhile
write-message &cat %count " files moved"
!else
D-getfile
set %move @&cat &cat "Move or Rename" %shortfile " to: "
!if &seq %move ".."
set %move &cat %dir "/.."
!endif
!if &seq &left %move 2 "~~/"
set %move &cat %home &right %move &sub &len %move 1
!else
!if &equ &sind %move "/" 0
set %move &cat &cat %dir "/" %move
!endif
!endif
shell-command &cat &cat &cat "mv -i " %filename " " %move
unmark-buffer %Dbuffer
!endif
D-revert
!break
!endif
; =======Mark File====== ---"m"---
!if &or &seq %key "m" &seq %key "d"
beginning-of-line
set %markq &left #%Dbuffer 3
previous-line
beginning-of-line
!if &seq %markq %markstr
write-message "file already marked"
!else
!force 3 forward-character
3 delete-previous-character
insert-string %markstr
set %marked &add %marked 1
!if ¬ &equ $curline %lastline
next-line
!endif
beginning-of-line
!force %ncol forward-character
write-message &cat %marked " marked files"
unmark-buffer %Dbuffer
!endif
!goto endproc
!endif
; =======Unmark file===== ---"u"---
!if &seq %key "u"
beginning-of-line
set %markq &left #%Dbuffer 3
previous-line
beginning-of-line
!if &seq %markq " "
write-message "file not marked"
!else
3 forward-character
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
beginning-of-line
next-line
!force %ncol forward-character
write-message &cat %marked " marked files"
unmark-buffer %Dbuffer
!endif
!goto endproc
!endif
; =======Revert Buffer===== ---"g"---
!if &seq %key "g"
D-revert
!break
!endif
; =======Make Sub-Directory===== ---"+"---
!if &seq %key "+"
set %mkdir @&cat &cat "Make sub-directory: " %dir "/"
shell-command &cat &cat &cat "mkdir " %dir "/" %mkdir
D-revert
!break
!endif
; =======Execute file===== ---"a"---
!if &seq %key "a"
D-getfile
set %done TRUE
execute-file %filename
!break
!endif
; =======Compress===== ---"C"---
!if &seq %key "C"
!if &gre %marked 0
set %compq @"Compress marked files? [y/n]: "
!if &seq &low %compq "y"
write-message "uncompressing marked files..."
set %count 0
!while &gre %marked 0
beginning-of-file
search-forward %markstr
D-getfile
shell-command &cat "compress " %filename
beginning-of-line
3 forward-character
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
set %count &add %count 1
!endwhile
write-message &cat %count " files compressed"
!endif
!else
D-getfile
set %compq @&cat &cat "Compress " %filename "? [y/n]: "
!if &seq &low %compq "y"
shell-command &cat "compress " %filename
!endif
!endif
set %compq " "
D-revert
!break
!endif
; =======Un-Compress===== ---"U"---
!if &seq %key "U"
!if &gre %marked 0
set %compq @"Uncompress marked files? [y/n]: "
!if &seq &low %compq "y"
write-message "uncompressing marked files..."
!while &gre %marked 0
beginning-of-file
search-forward %markstr
D-getfile
shell-command &cat "uncompress " %filename
beginning-of-line
3 forward-character
3 delete-previous-character
insert-string " "
set %marked &sub %marked 1
!endwhile
!endif
!else
D-getfile
set %compq @&cat &cat "Uncompress " %filename "? [y/n]: "
!if &seq &low %compq "y"
shell-command &cat "uncompress " %filename
!endif
!endif
set %compq " "
D-revert
!break
!endif
; =======Tar===== ---"t"---
!if &seq %key "t"
D-getfile
!if &seq &right %filename 4 ".tar"
D-tarview
!break
!else
!if ¬ &seq %cwd %dir
write-message &cat "Abort: must be in " %cwd
!goto endtar
!endif
!if &gre %marked 0
set %tarc @"new archive name (.tar added)? : "
!if &seq &left %tarc 2 "~~/"
set %tarc &cat %home &right %tarc &sub &len %tarc 1
!else
!if &equ &sind %tarc "/" 0
set %tarc &cat &cat %dir "/" %tarc
!endif
!endif
set %tarc &cat %tarc ".tar"
write-message &cat &cat "Tarring marked files into " %tarc "..."
set %count 0
!while &gre %marked 0
beginning-of-file
search-forward %markstr
D-getfile
beginning-of-line
3 forward-character
3 delete-previous-character
insert-string " "
shell-command &cat &cat "echo " %shortfile " >> TARLIST"
set %marked &sub %marked 1
set %count &add %count 1
!endwhile
set %marked 0
shell-command &cat &cat "tar cf " %tarc " -I TARLIST"
shell-command "rm TARLIST"
write-message &cat &cat %count " files tarred in " %tarc
!else
D-getfile
set %tarc &cat &cat &cat %dir "/" %filename ".tar"
write-message &cat &cat "Tarring " %shortfile "..."
shell-command &cat &cat "tar cf " %tarc %shortname
!endif
!endif
D-revert
!break
*endtar
!endif
; =======Un-Tar===== ---"e"---
!if &seq %key "e"
!if ¬ &seq %cwd %dir
write-message &cat "Abort: Files would be extracted into " %cwd
!goto enduntar
!endif
D-getfile
write-message &cat &cat "Extracting " %shortfile "..."
shell-command &cat "tar xf " %filename
D-revert
!break
*enduntar
!endif
; =======Exit Dired Mode ---"z"---
!if &seq %key "z"
write-message "Dired OFF... (C-x C-d to resume)"
set %done TRUE
!break
!endif
; =======Find file===== C-x C-f
!if &seq %cmd "find-file"
set %cmd " "
set %newbuf @"Find file: "
!if &seq &left %newbuf 2 "~~/"
set %newbuf &cat %home &right %newbuf &sub &len %newbuf 1
!else
!if &equ &sind %newbuf "/" 0
set %newbuf &cat &cat %dir "/" %newbuf
!endif
!endif
!force find-file %newbuf
set %done TRUE
!break
!endif
; =======Pass commands=====
!if &seq %cmd "delete-buffer"
set %done TRUE
next-buffer
delete-buffer %Dbuffer
!endif
!if &seq %cmd "[D-open]"
!force D-open
!endif
!if &seq %cmd "[mouse-clicks]"
!force mouse-move-down
!goto endproc
!endif
!if &seq %cmd "[toggle-fkeys]"
execute-procedure "toggle-fkeys"
!goto endproc
!endif
!if &seq %cmd "[get-help]"
execute-procedure "get-help"
!goto endproc
!endif
!if &seq %cmd "next-buffer"
set %done TRUE
unmark-buffer %Dbuffer
next-buffer
!goto endproc
!endif
!if &seq %cmd "[kill-this-one]"
set %done TRUE
set %cmd " "
execute-procedure kill-this-one
!goto endproc
!endif
!force execute-named-command %cmd
*endproc
!endwhile
!endm
; ==============D-getfile
store-procedure D-getfile
end-of-line
!if &les $curcol %ncol
write-message "Not positioned on file or directory"
!goto endget
!endif
beginning-of-line
3 forward-character
set %dirq &left #%Dbuffer 1
previous-line
beginning-of-line
!force %ncol forward-character
set %filename &trim #%Dbuffer
!if &seq %dirq "d"
!if &seq %filename "."
write-message "Tried to load ~".~" (use g to revert buffer to refresh)"
previous-line
!force %ncol forward-character
set %dot TRUE
!goto endget
!endif
!if &seq %filename ".."
set %testdir %dir
set %orgdir %testdir
set %dirlen &len %testdir
set %orglen %dirlen
set %slash &sind %testdir "/"
!while ¬ &equ %slash 0
set %testdir &right %testdir &sub %dirlen %slash
set %dirlen &len %testdir
set %slash &sind %testdir "/"
!endwhile
write-message &left %orgdir &sub %orglen &add 1 &len %testdir
set %newdir &left %orgdir &sub %orglen &add 1 &len %testdir
!else
set %newdir &cat &cat %dir "/" %filename
!endif
!else
set %shortfile %filename
set %filename &cat &cat %dir "/" %filename
set %dirq " "
!endif
previous-line
!force %ncol forward-character
*endget
!endm
; ==============D-load-file
store-procedure D-load-file
!if &seq %dot FALSE
!if &seq %dirq "d"
!force delete-buffer &cat "Dired-" %newdir
set %dirq " "
set %dir %newdir
!if %revert FALSE
write-message &cat &cat "[Reading " %dir "...]"
!endif
set %done TRUE
D-window
!else
write-message &cat &cat "[Reading " %filename "...]"
!if &seq %othwin FALSE
delete-other-windows
!else
set %othwin FALSE
!endif
!force find-file %filename
set %done TRUE
!endif
!endif
set %dot FALSE
*loadend
!endm
; ==============D-delete
store-procedure D-delete
write-message &cat &cat "Deleting " %filename "..."
shell-command &cat &cat "rm " %filename
beginning-of-line
1 kill-to-end-of-line
set %lastline &sub %lastline 1
update-screen
unmark-buffer %Dbuffer
!endm
; ==============D-tarview
store-procedure D-tarview
set %cmd " "
!force pipe-command &cat "tar tvf " %filename
set %done TRUE
name-buffer %shortfile
change-file-name "tar-view"
beginning-of-file
insert-string &cat &cat "=== Contents of tarfile: " %shortfile " ===~n~n"
update-screen
!endm
store-procedure D-revert
set %revert TRUE
set %oldline $curline
name-buffer "stale"
unmark-buffer "stale"
D-window
!endm
set $discmd FALSE
macro-to-key D-open ^XD
macro-to-key D-check ^X^D
set $bufhook D-check
set $discmd TRUE
;write-message "...done (C-x d to open directory)"