home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / cmdpk164.zip / profilec.shl < prev    next >
Text File  |  1998-01-10  |  19KB  |  294 lines

  1. /* This is a commented version of CommandPak's default profile.       */
  2. /* (W) 1997-98 Martin Lafaix, Ulrich Möller                           */
  3.  
  4. /* There are zillions of comments in this file. There's another       */
  5. /* version without the comments to speed up processing (profile.shl). */
  6.  
  7. /* This file is based on Martin Lafaix' original profile.             */
  8. /* A large number of things have been added to incorporate            */
  9. /* CommandPak's functions into CmdShl's context.                      */
  10. /* All changes made by Ulrich Möller are marked with (UM).            */
  11. /* ML's French help messages have been moved into XHELP033.MSG.       */
  12. /* Everything else is written by Martin Lafaix, namely the following: */
  13.  
  14. /* This profile file demonstrates typical profile usage:              */
  15. /*                                                                    */
  16. /*       - Improving/tailoring existing commands, adding shortcuts    */
  17. /*         [The auto-close '(', the insert-date key (F8), and S-F7,   */
  18. /*         which displays all possible filenames.]                    */
  19. /*                                                                    */
  20. /*       - Adding new functions                                       */
  21. /*         [The persistent command history, F2 (save), F5 (load) and  */
  22. /*         F7 (name), tools to search items through command history   */
  23. /*         as well as screen management system with C-UP, C-DOWN and  */
  24. /*         C-PADPLUS.]                                                */
  25. /*                                                                    */
  26. /*       - National Language Support                                  */
  27. /*         [on-line messages in French.]                              */
  28. /*                                                                    */
  29. /*       - Useful global aliases and rules                            */
  30.  
  31. /* In a profile file, you can use any REXX instruction, but, due to   */
  32. /* the current implementation, it must fit in one line.               */
  33. /*                                                                    */
  34. /* That is, you can use:                                              */
  35. /*                                                                    */
  36. /*     if foo = 'XYZZY' then say 'Nothing happens'; else  x = x + 1   */
  37. /*                                                                    */
  38. /* But you can't use:                                                 */
  39. /*                                                                    */
  40. /*     if foo = 'XYZZY' then                                          */
  41. /*        say 'Twice as much happens'                                 */
  42. /*     else                                                           */
  43. /*        x = x + 1                                                   */
  44. /*                                                                    */
  45. /* Alternatively, you can use the comma as a line continuation marker */
  46. /*                                                                    */
  47. /*     foo = 'Hello',                                                 */
  48. /*           'world'                                                  */
  49. /*                                                                    */
  50. /* Another important difference with standard REXX scripts is that    */
  51. /* you cannot call CmdShl commands in a REXX structure using the      */
  52. /* standard way.  You have to use the eval function.  That is,        */
  53. /*                                                                    */
  54. /*     if answer = 'YES' then                                         */
  55. /*        'DEFINE F12 OSNOWAIT shutdown'                              */
  56. /*     else                                                           */
  57. /*        'DEFINE F12 TEXT shutdown'                                  */
  58. /*                                                                    */
  59. /* does not work.  You have to use:                                   */
  60. /*                                                                    */
  61. /*     if answer = 'YES' then                                         */
  62. /*        call eval 'DEFINE F12 OSNOWAIT shutdown'                    */
  63. /*     else                                                           */
  64. /*        call eval 'DEFINE F12 TEXT shutdown'                        */
  65. /*                                                                    */
  66. /* [But it works just fine outside of a structure.]                   */
  67.  
  68.  
  69. /* Note: when a command name is in mixed case, like DEFine below, it  */
  70. /*       means that you can use DEF, DEFI, DEFIN or DEFINE.           */
  71.  
  72. /*                                                                    */
  73. /* There's currently only one "pseudo" command, DEFine, which is most */
  74. /* useful in profile file. Its syntax is as follows:                  */
  75. /*                                                                    */
  76. /*     DEFine key value                                               */
  77. /*                                                                    */
  78. /* Key is a user-defined key or a predefined one:                     */
  79. /*                                                                    */
  80. /*     A-F10, BKSP, CURD, CURL, CURR, CURU, C-CURL, C-CURR, C-END,    */
  81. /*     C-HOME, C-PGDN, C-PGUP, DEL, END, ENTER, ESC, F1, F2, F3, F4,  */
  82. /*     F5, F6, F7, F8, F9, F10, F11, F12, HOME, INS, PGDN, PGUP,      */
  83. /*     SPACE, S-TAB, TAB                                              */
  84. /*                                                                    */
  85. /*     [Shifted keys have a "S-" prefix, control keys have a "C-"     */
  86. /*      prefix and Alt keys have a "A-" prefix.]                      */
  87. /*                                                                    */
  88. /* and value is an internal action or MC nnn, OSNowait nnn or         */
  89. /* TEXT nnn:                                                          */
  90. /*                                                                    */
  91. /*     backmatch, backsp, cdown, cleft, cright, ctrlend, ctrlhome,    */
  92. /*     ctrlleft, ctrlright, cup, del, end, enter, esc, match, home,   */
  93. /*     ins, tab, space, expand                                        */
  94. /*                                                                    */
  95. /*     TEXT nnn simulates the keyboard entry of nnn                   */
  96. /*                                                                    */
  97. /*     OSNowait cmd executes cmd (via the CmdShl interpreter)         */
  98. /*                                                                    */
  99. /*     MC separator cmd1 separator cmd2... allows the usage of more   */
  100. /*     than one command for a key                                     */
  101. /*                                                                    */
  102. /* All other "pseudo" commands are executed via CmdShl's interpreter. */
  103.  
  104. /* [In fact, the DEFine command could have been implemented as an     */
  105. /*  alias:                                                            */
  106. /*                                                                    */
  107. /*     ALIAS DEFINE=RX _args="%*";                                    */
  108. /*                     parse value _args with key rest;               */
  109. /*                     if length(key) > 1 then                        */
  110. /*                        key = value(translate(key,"_","-"));        */
  111. /*                     if rest \= "" then                             */
  112. /*                        call value "key._"c2x(key), rest;           */
  113. /*                     else interpret "drop key._"c2x(key)            */
  114. /*                                                                    */
  115. /*  It is functionally equivalent.]                                   */
  116.  
  117. /* user-defined key name - note the usage of "_" in place of "-" in   */
  118. /*                         the key name (you can't use "-" in a REXX  */
  119. /*                         variable name).                            */
  120. /*                                                                    */
  121. /*                         The value of a key name is the hexadecimal */
  122. /*                         value returned by the getKey function when */
  123. /*                         pressing it (you can use the following     */
  124. /*                         CmdShl command to find it) :               */
  125. /*                                                                    */
  126. /*                         RX call getkey; say "'"substr(ckey,2)"'x"  */
  127.  
  128. /* Note: by default, variables are hidden when inside a getLine call. */
  129. /*       If you want to expose some of them, add them to the global   */
  130. /*       variable -- global = global "newname1 newname2"              */
  131. /*                                                                    */
  132. /*       So, each time you use one of your variable in the right hand */
  133. /*       side of a DEFine command, you have to expose it.             */
  134.  
  135. /* (UM) Now we're starting up. Issue a message where from CmdSHl is.  */
  136. parse Source . . myFile; call charout , myFile': Entering profile... '
  137.  
  138. /* (UM) If you like, uncomment the following to play a little sound.  */
  139. /* SysBootDrive() requires ObjectREXX or Warp 4.                      */
  140. /* n=SysBootDrive(); 'start /n /min cmd.exe /c 'n'\mmos2\play.cmd file=e:\common\waves\doink.wav' */
  141.  
  142. /* COMMAND HISTORY FUNCTION                                           */
  143. /* ========================                                           */
  144. /* Original by Martin Lafaix, extended by (UM)                        */
  145.  
  146. /* now, we define a file name (and make it public, F7 requires it):   */
  147. history = expand('%TMP%\history.shl'); global = global 'history'
  148.  
  149. 'ALIAS LOADHIST=RX call charout , "  Loading history..."; drop prevLine.; i = 0; do while lines(history); i = i+1; prevLine.i = linein(history); end; prevLine.0 = i; call stream history, "c", "close"; say " done."'
  150. 'ALIAS SAVEHIST=RX call charout , "  Saving history..."; "@if exist" history "del /f" history; xx = (prevLine.0)-100; if (xx<1) then xx=1; do i = xx to prevline.0; call lineout history, prevLine.i; end; call stream history, "c", "close" ; say " done."'
  151.  
  152. /* now we redefine "exit" and lay it on certain keys (UM)             */
  153. exitList = 'SAVEHIST'; global = global 'exitList'
  154. 'ALIAS exit=RX call charout , "Exiting..."; call eval(exitList); "exit"'
  155. /* defining key value - a shifted key can use "-" or "_" in its name  */
  156. S_F7 = '005A'x; C_CURU = '008D'x; C_CURD = '0091'x; C_PADPLUS = '0090'x; A_F4 = '006b'x
  157. 'DEFINE F3 SHELL exit'
  158. 'DEFINE A-F4 SHELL exit'
  159.  
  160. 'DEFINE F2 OSNOWAIT SAVEHIST'
  161. 'DEFINE F5 OSNOWAIT LOADHIST'
  162. 'DEFINE F7 OSNOWAIT RX call charout ,"1b"x"[s"||"1b"x"[0;0H"||"1b"x"[1;37;42m"||"1b"x"[KNew history name: "; history=getLine(history); call charout ,"1b"x"[0;0H"||"1b"x"[0;34;47m"||"1b"x"[K"helpstring"1b"x"[0m"||"1b"x"[u"'
  163.  
  164. /* finally, we load the default history                               */
  165. 'LOADHIST'
  166.  
  167. /* We define tools to search through command history.                 */
  168. C_F = '06'x; C_R = '12'x; global = global 'item'; item = ''
  169. 'DEFINE C-R OSN RX oldLine=currLine;call charout ,"1b"x"[s"||"1b"x"[0;0H"||"1b"x"[1;37;42m"||"1b"x"[KSearch for: "; item=getLine(item); call charout ,"1b"x"[0;0H"||"1b"x"[0;34;47m"||"1b"x"[K"helpstring"1b"x"[0m"||"1b"x"[u";',
  170.            'if item \= "" then do;prevLine.0=prevLine.0-1;currLine=oldLine-1;if currLine=0 then currLine=prevLine.0;do prevLine.0 while pos(item,prevLine.currLine) = 0;currLine = currLine-1;',
  171.            'if currLine=0 then currLine=prevLine.0;end;if pos(item,prevLine.currLine) \= 0 then line=prevLine.currLine;currOfs=length(line);xOfs=0;end'
  172. 'DEFINE C-F OSN RX if item\="" then do; oldCur=currLine;currLine = currLine-1;if currLine = 0 then currLine=prevLine.0;',
  173.            'do prevLine.0 while pos(item,prevLine.currLine) = 0;currLine = currLine-1;if currLine=0 then currLine=prevLine.0;end;if pos(item,prevLine.currLine) \= 0 then line=prevLine.currLine;currOfs=length(line);xOfs=0; end'
  174.  
  175. /* SCREEN MANAGEMENT                                                  */
  176. /* =================                                                  */
  177.  
  178. /* We can even define a screen management system.                     */
  179. scr.0 = 0; global = global 'scr.'
  180.  
  181. 'ALIAS PUSHSCR=RX i = scr.0 + 1; scr.i._C = SysCurPos(); scr.i._P = currOfs origRow origCol; scr.i._L = line; scr.i._S = VioReadCellStr(0,0); scr.i._O = oldDir; scr.i._D = directory(); scr.0 = i'
  182. 'ALIAS POPSCR=RX i = scr.0; if i > 0 then do; call VioWrtCellStr 0,0,scr.i._S; line = scr.i._L; call SysCurPos word(scr.i._c,1), word(scr.i._c,2); parse var scr.i._P currOfs origRow origCol; oldDir = scr.i._O; call directory scr.i._D; scr.0 = i-1; end'
  183. 'ALIAS SWAPTMPSCR=RX i = scr.0 + 1; scr.i._C = scr._C; scr.i._P = scr._P; scr.i._L = scr._L; scr.i._S = scr._S; scr.i._O = scr._O; scr.i._D = scr._D; scr.0 = i'
  184. 'ALIAS SWAPSCR=RX if scr.0 > 0 then do; scr._C = SysCurPos(); scr._P = currOfs origRow origCol; scr._L = line; scr._S = VioReadCellStr(0,0); scr._O = oldDir; scr._D = directory(); call eval "POPSCR & SWAPTMPSCR"; end'
  185.  
  186. 'DEFINE C-CURD SHELL PUSHSCR'
  187. 'DEFINE C-CURU SHELL POPSCR'
  188. 'DEFINE C-PADPLUS SHELL SWAPSCR'
  189.  
  190. /* MISCELLANEA                                                        */
  191. /* ===========                                                        */
  192.  
  193. /* We redefine C-K to a smarter duplication function.                 */
  194. 'DEFINE C-K MC /dup/tab'
  195.  
  196. /* you can even do complex things:                                    */
  197. 'DEFINE (  MC /TEXT ()/cleft'
  198. 'DEFINE F8 SHELL RX line = insert(date(),line,currOfs); currOfs = currOfs+length(date())'
  199. 'DEFINE S-F7 osn rx if currTab = 0 then currTab = findcontextcompletion(); if currTab \= 0 then do; say; do i = 1 to tree.0; say tree.i; end; call charout, print(); oline=""; parse value SysCurPos() with origRow origCol .; key="tab"; end'
  200.  
  201. /* (UM) here comes the new RECURSE command; see CommandPak's online help   */
  202. 'ALIAS recurse=rx rargs = "%*"; if ((rargs="") | left(rargs, 1)="-") then "call xhelp recurse";',
  203.            'else do; signal on halt; rcurd = directory(); Call charout ,"Collecting directories... "; call SysFileTree "*", dirs ,"DSO"; Say "Done.";',
  204.            'do i_ = 1 to dirs.0; signal on halt; say "["dirs.i_"] >"rargs; call directory dirs.i_; call eval rargs" ^& rx needCR=0"; end; call directory rcurd; end; '
  205. 'ALIAS rec=recurse %*'
  206.  
  207. /* (UM) here comes the new OPEN command; see CommandPak's online help      */
  208. 'ALIAS open=rx what = "%*"; ocurd = directory(); if (left(what, 1)="-") then "call xhelp open"; else do; if (what = "") then what = ocurd;',
  209.            'signal on halt; call eval "cd" what; call charout , "Trying to open "directory()"... "; ',
  210.            'if SysSetObjectData(directory(),"OPEN=DEFAULT") then say "OK."; else say "failed."; call directory ocurd; end '
  211. /* (UM) set a RULE: browse through directories only */
  212. 'RULE open=%d'
  213.  
  214. /* netscape is used so that you can simply enter                      */
  215. /* "netscape index.html" instead of "netscape file:index.html" which  */
  216. /* is required by Netscape if you don't want to receive an error      */
  217. /* message. If you specify an URL instead of a file name, it still    */
  218. /* works, too.                                                        */
  219. 'ALIAS netscape=rx url=stream("%1", "c", "query exists"); if url="" then call eval("start netscape.exe %1"); else call eval("start netscape.exe" url)'
  220.  
  221. /* loop allows you to do a command more than once.  Please note that  */
  222. /* it requires a REXX syntax.   For example,                          */
  223. /* "loop 10; 'mp123 Lillith.mp3'; end" will play the Lillith song ten */
  224. /* times. [Lillith is a track from Plaid's album "Not For Threes",    */
  225. /* featuring Björk.]                                                  */
  226. 'ALIAS loop=rx do %*'
  227.  
  228. 'ALIAS qd=query date'
  229. 'ALIAS qt=query time'
  230.  
  231. /* useful rule... from my point of view :-) */
  232. 'RULE WHENCE=%f %e'
  233. 'RULE recurse=%x'
  234.  
  235. /* CONFIG EXTERNAL PROGRAMS                                           */
  236. /* ========================                                           */
  237.  
  238. /* (UM) now we set up common stuff for SDir/xdir                           */
  239. 'SET DIRCLR.ATTRIB=D:cyan;S,R,H:on red'
  240. 'SET DIRCLR.DATE=-3:on blue'
  241. 'SET DIRCLR.EXT=BAT,EXE,COM,CMD:bright red'
  242. 'SET DIRCLR.WPABSTRACT=green'
  243. 'SET CMDSHL.PROMPT=cmdshl $p$g'
  244.  
  245. /* (UM) uncomment the following to set xdir's default output to UNIX fmt.  */
  246. /* 'SET  XDIR.DIRCMD=-C' */
  247.  
  248. /* (UM) Now configure the help system (xhelp.cmd). See CommandPak's online */
  249. /* help for details on supported environment variables.               */
  250. /* Typing 'help cmdshl' or 'help ref' will bring up three books:      */
  251. 'SET HELP.REF=cmdpak0+mlrxshl+cmdpak'
  252. 'SET HELP.CMDSHL=cmdpak0+mlrxshl+cmdpak'
  253. /* Make MLRXSHL's commands support xhelp:                             */
  254. 'SET HELP.COMMAND=xhelp'
  255. 'SET HELP.SWITCHES=/? -h --help'
  256. helpSwitches = '/? -h --help'
  257. /* Now make xhelp's output a little more colorful:                    */
  258. 'SET HELP.ANCHOR=on blue'
  259. 'SET HELP.BOLD=bright'
  260. 'SET HELP.ITALICS=cyan'
  261. /* The following sets the English message file used for xhelp,        */
  262. /* in this case XHELP001.MSG:                                         */
  263. 'SET HELP.COUNTRY=001'
  264. /* 'SET HELP.COUNTRY=049' would be German (XHELP049.MSG)              */
  265.  
  266. /* (UM) Replace standard commands -- since aliases are case-sensitive, you */
  267. /* can still call OS/2's originals by capitalizing them:              */
  268. 'ALIAS dir=xdir %*'
  269. 'ALIAS ren=xren %*'
  270. 'ALIAS copy=xcp %*'
  271. 'ALIAS help='SysSearchPath('PATH', 'xhelp.cmd')' %*'
  272.  
  273. /* (UM) some more aliases--more UNIX-like:                            */
  274. 'ALIAS ls=xdir %*'
  275. 'ALIAS mv=xren %*'
  276. 'ALIAS cp=xcp %*'
  277. 'ALIAS ?=xhelp %*'
  278.  
  279. /* (UM) make cmdshl execute commands before directories               */
  280. impCD = 2
  281.  
  282. /* (UM) Make your favorite editor react to "e"                        */
  283. /* ALIAS e=start /f <insert your favorite editor here>                */
  284. /* Shortcuts: e0: profile; e1: CONFIG.SYS; e2: AUTOEXEC.BAT           */
  285. /* SysBootDrive works on Warp 4 or Warp 3 w/ ObjectREXX only          */
  286. "ALIAS e0=RX call eval('e' SysSearchPath('DPATH', 'profile.shl'))"
  287. "ALIAS e1=RX call eval('e' SysBootDrive()||'\config.sys')"
  288. "ALIAS e2=RX call eval('e' SysBootDrive()||'\autoexec.bat')"
  289. 'ALIAS e3=e "H:\develop\distribute\cmdshl\ToDo list.shl"'
  290.  
  291. /* (UM) Finally, say hello: */
  292. 'help -w'
  293.  
  294.