Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Rebol Windows shell

From: bry::itnisk::com at: 5-Sep-2004 15:22

-- Bryan Rasmussen I have added slightly to the RESH.R script found here and done some additions to the registry so as to improve its usage, my rebol additions are of course pedestrian and boring, here is the version I am using (I removed some of the original comments as it made it difficult for me to follow): Rebol[] {LOOK AT SOME EXAMPLES ABOUT THE POWER OF RESH (EXAMPLES MADE UNDER MS WINDOWS ENVIRONMENT). Read directory "C:\", find out the dirs, then call MsDOS "DIR" command to show its contents
>> foreach x read %/c/ [if (last x) = #"/" [resh rejoin ["dir c:\" copy/part x
((length? x) - 1)] ] ] Read the directory contained in Rebol variable "a"
>> a: [to-local-file %/c/temp/] >> dir (/a/)
} do %user-commands.r ;added by me messages: "success" is-script: True argsstring: "" argsstring: to-string system/script/args isfile: True if error? try [ the-file: read to-file argsstring isfile: True the-folder: dirize to-rebol-file first split-path to-file argsstring ][ the-file: "The file could not be read" the-folder: dirize to-rebol-file argsstring isfile: False] if error? try [do to-file argsstring][messages: "cannot DO input" is-script: False ] argsstring: to-string argsstring ; end addition ReSH: func ["This function let you run SYSTEM commands." command [string!] /col "Read a output column (from-top from-bottom column-number)" from-top from-bottom col-num [integer! block!] /out "Store data in resh-out variable"] [ if error? result: try [ if error? result: try [ do command 0] [ if error? result: try [ disarm result do to-block command ] [ disarm result parsed: parse/all command "()" forall parsed [ if all [(last first parsed) = #"/" (first first parsed) = #"/" ] [res: (copy/part next first parsed (length? next first parsed) - 1) change first parsed (do do load to-block res) ]] parsed: head parsed parsed: rejoin parsed print ^/----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 if out [ resh-out: make block! 1000 ] ; /COL refiniment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; either col [ reshTemp: make string! 1000 call/output parsed reshTemp tempParse: parse/all reshTemp "^/" tempParse: skip tempParse from-top tempParse: copy/part tempParse ( (length? tempParse) - from-bottom) foreach x tempParse [ line: parse x none either (type? col-num) = integer! [ print line/:col-num ] [ if (type? col-num) = block! [ foreach col col-num [ either (type? col) = integer! [ prin rejoin [line/:col tab] ] [ prin rejoin [copy/part skip x (col/1 - 1) col/2 tab] ];either ];foreach print "" ];if ];either if out [ append/only resh-out line ] ] ] [ either out [ ; /OUT refiniment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; reshTemp: make string! 1000 call/output parsed reshTemp tempParse: parse/all reshTemp "^/" foreach x tempParse [ line: parse x none append/only resh-out line print line ];foreach ] [ call/console parsed ; Try to exec as an external command ] ] print "/\ /\ /\ /\ /\ /\ /\ /\ /\ /\^/" 0 ] ] ] [ probe disarm result ] ];end of function ;============================================================================= command: make string! 100 lastPath: what-dir print messages forever [ oldCommand: copy command command: ask rejoin [the-folder " > "] ReSH command recycle ];forever --------------------------------------------------------- As can be seen the only real additions I made was some reading of command line arguments and some poor message writing on top before the RESH prompt is displayed. The command line gets passed to RESH when it is opened, and is controlled by the following registry settings: [HKEY_CLASSES_ROOT\*\Shell\rebCmd] @="rebCmd" [HKEY_CLASSES_ROOT\*\Shell\rebCmd\Command] @="D:\\programLanguages\\dynamic\\rebol\\view\\rebol.exe D:\\programLanguages\\dynamic\\rebol\\view\\resh.r %1" The above keys allows you to right click on a file and open it with RESH via the the context menu addition rebCMD in this case the following will happen: if you open a script it will be done unless doing so raises errors, for example if the script has words declared the same as words declared in RESH, and the value of is-script will be true. if the script raises errors the messages word will have "cannot DO input" the value of the-file will be the read in value of the file opened. the value of isfile will be True the-folder will hold the path to the folder in which the file was found, you can list the contents of this folder using list-dir the-folder [HKEY_CLASSES_ROOT\Folder\shell\rebCMD\Command] @="D:\\programLanguages\\dynamic\\rebol\\view\\rebol.exe D:\\programLanguages\\dynamic\\rebol\\view\\resh.r %1" the above key allows you to right click on a folder and open RESH in such a case the value of the-file will be the string "The file could not be read" the-folder will be the path to the folder located. In both cases the path shown at the RESH prompt will be the path of the-folder as opposed to previously when it showed the folder path where RESH was located. I have also used this technique to support using various Python interpreters as shells, but I think that Rebol's large number of built in networking functions etc. makes it more useful as a shell. I hope that others find this useful and hopefully will clean up my additions to the code, as well as perhaps extending the RESH shell as i think it could be beneficial to spreading Rebol adoption if it became a real top-notch shell replacement.