home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / cmdpk164.zip / profile1.shl < prev    next >
Text File  |  1997-12-10  |  16KB  |  247 lines

  1. /* profile.shl - sample bindings                               971208 */
  2.  
  3.  
  4. /* This profile file demonstrates typical profile usage:              */
  5. /*                                                                    */
  6. /*       - Improving/tailoring existing commands, adding shortcuts    */
  7. /*         [The auto-close '(', the insert-date key (F8), and S-F7,   */
  8. /*         which displays all possible filenames.]                    */
  9. /*                                                                    */
  10. /*       - Adding new functions                                       */
  11. /*         [The persistent command history, F2 (save), F5 (load) and  */
  12. /*         F7 (name), tools to search items through command history   */
  13. /*         as well as screen management system with C-UP, C-DOWN and  */
  14. /*         C-PADPLUS.]                                                */
  15. /*                                                                    */
  16. /*       - National Language Support                                  */
  17. /*         [on-line messages in French.]                              */
  18. /*                                                                    */
  19. /*       - Useful global aliases and rules                            */
  20.  
  21.  
  22. /* In a profile file, you can use any REXX instruction, but, due to   */
  23. /* the current implementation, it must fit in one line.               */
  24. /*                                                                    */
  25. /* That is, you can use:                                              */
  26. /*                                                                    */
  27. /*     if foo = 'XYZZY' then say 'Nothing happens'; else  x = x + 1   */
  28. /*                                                                    */
  29. /* But you can't use:                                                 */
  30. /*                                                                    */
  31. /*     if foo = 'XYZZY' then                                          */
  32. /*        say 'Twice as much happens'                                 */
  33. /*     else                                                           */
  34. /*        x = x + 1                                                   */
  35. /*                                                                    */
  36. /* Alternatively, you can use the comma as a line continuation marker */
  37. /*                                                                    */
  38. /*     foo = 'Hello',                                                 */
  39. /*           'world'                                                  */
  40. /*                                                                    */
  41. /* Another important difference with standard REXX scripts is that    */
  42. /* you cannot call CmdShl commands in a REXX structure using the      */
  43. /* standard way.  You have to use the eval function.  That is,        */
  44. /*                                                                    */
  45. /*     if answer = 'YES' then                                         */
  46. /*        'DEFINE F12 OSNOWAIT shutdown'                              */
  47. /*     else                                                           */
  48. /*        'DEFINE F12 TEXT shutdown'                                  */
  49. /*                                                                    */
  50. /* does not work.  You have to use:                                   */
  51. /*                                                                    */
  52. /*     if answer = 'YES' then                                         */
  53. /*        call eval 'DEFINE F12 OSNOWAIT shutdown'                    */
  54. /*     else                                                           */
  55. /*        call eval 'DEFINE F12 TEXT shutdown'                        */
  56. /*                                                                    */
  57. /* [But it works just fine outside of a structure.]                   */
  58.  
  59.  
  60. /* Note: when a command name is in mixed case, like DEFine below, it  */
  61. /*       means that you can use DEF, DEFI, DEFIN or DEFINE.           */
  62.  
  63. /*                                                                    */
  64. /* There's currently only one "pseudo" command, DEFine, which is most */
  65. /* useful in profile file. Its syntax is as follows:                  */
  66. /*                                                                    */
  67. /*     DEFine key value                                               */
  68. /*                                                                    */
  69. /* Key is a user-defined key or a predefined one:                     */
  70. /*                                                                    */
  71. /*     A-F10, BKSP, CURD, CURL, CURR, CURU, C-CURL, C-CURR, C-END,    */
  72. /*     C-HOME, C-PGDN, C-PGUP, DEL, END, ENTER, ESC, F1, F2, F3, F4,  */
  73. /*     F5, F6, F7, F8, F9, F10, F11, F12, HOME, INS, PGDN, PGUP,      */
  74. /*     SPACE, S-TAB, TAB                                              */
  75. /*                                                                    */
  76. /*     [Shifted keys have a "S-" prefix, control keys have a "C-"     */
  77. /*      prefix and Alt keys have a "A-" prefix.]                      */
  78. /*                                                                    */
  79. /* and value is an internal action or MC nnn, OSNowait nnn or         */
  80. /* TEXT nnn:                                                          */
  81. /*                                                                    */
  82. /*     backmatch, backsp, cdown, cleft, cright, ctrlend, ctrlhome,    */
  83. /*     ctrlleft, ctrlright, cup, del, end, enter, esc, match, home,   */
  84. /*     ins, tab, space, expand                                        */
  85. /*                                                                    */
  86. /*     TEXT nnn simulates the keyboard entry of nnn                   */
  87. /*                                                                    */
  88. /*     OSNowait cmd executes cmd (via the CmdShl interpreter)         */
  89. /*                                                                    */
  90. /*     MC separator cmd1 separator cmd2... allows the usage of more   */
  91. /*     than one command for a key                                     */
  92. /*                                                                    */
  93. /* All other "pseudo" commands are executed via CmdShl's interpreter. */
  94.  
  95. /* [In fact, the DEFine command could have been implemented as an     */
  96. /*  alias:                                                            */
  97. /*                                                                    */
  98. /*     ALIAS DEFINE=RX _args="%*";                                    */
  99. /*                     parse value _args with key rest;               */
  100. /*                     if length(key) > 1 then                        */
  101. /*                        key = value(translate(key,"_","-"));        */
  102. /*                     if rest \= "" then                             */
  103. /*                        call value "key._"c2x(key), rest;           */
  104. /*                     else interpret "drop key._"c2x(key)            */
  105. /*                                                                    */
  106. /*  It is functionally equivalent.]                                   */
  107.  
  108. /* user-defined key name - note the usage of "_" in place of "-" in   */
  109. /*                         the key name (you can't use "-" in a REXX  */
  110. /*                         variable name).                            */
  111. /*                                                                    */
  112. /*                         The value of a key name is the hexadecimal */
  113. /*                         value returned by the getKey function when */
  114. /*                         pressing it (you can use the following     */
  115. /*                         CmdShl command to find it) :               */
  116. /*                                                                    */
  117. /*                         RX call getkey; say "'"substr(ckey,2)"'x"  */
  118.  
  119. /* Note: by default, variables are hidden when inside a getLine call. */
  120. /*       If you want to expose some of them, add them to the global   */
  121. /*       variable -- global = global "newname1 newname2"              */
  122. /*                                                                    */
  123. /*       So, each time you use one of your variable in the right hand */
  124. /*       side of a DEFine command, you have to expose it.             */
  125.  
  126.  
  127. S_F7 = '005A'x; C_CURU = '008D'x; C_CURD = '0091'x; C_PADPLUS = '0090'x
  128.  
  129. /* defining key value - a shifted key can use "-" or "_" in its name  */
  130. 'DEFINE F3 OSNOWAIT EXIT'
  131.  
  132.  
  133. /* you can even do complex things:                                    */
  134. 'DEFINE (  MC /TEXT ()/cleft'
  135.  
  136. 'DEFINE F8 OSNOWAIT RX line = insert(date(),line,currOfs); currOfs = currOfs+length(date())'
  137.  
  138. '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'
  139.  
  140.  
  141. /* we can even add a new feature: loading/saving commands history     */
  142.  
  143. /* first, we define a file name (and make it public, F7 requires it): */
  144. history = expand('%tmp%\history.shl'); global = global 'history'
  145.  
  146. /* then, an alias, LOADHIST, which loads the commands history         */
  147. 'ALIAS LOADHIST=RX drop prevLine.; i = 0; do while lines(history); i = i+1; prevLine.i = linein(history); end; prevLine.0 = i; call stream history, "c", "close"'
  148.  
  149. /* now, we define three function keys, F2 (save), F5 (load/refresh)   */
  150. /* and F7 (name)                                                      */
  151. 'DEFINE F2 OSNOWAIT RX "@del /f" history; do i = 1 to prevLine.0; call lineout history, prevLine.i; end; call stream history, "c", "close"'
  152. 'DEFINE F5 OSNOWAIT LOADHIST'
  153. '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"'
  154.  
  155. /* finally, we load the default history                               */
  156. 'LOADHIST'
  157.  
  158.  
  159. /* We can even define a screen management system.                     */
  160. scr.0 = 0; global = global 'scr.'
  161.  
  162. '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'
  163. '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'
  164. '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'
  165. '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'
  166.  
  167. 'DEFINE C-CURD OSNOWAIT PUSHSCR'
  168. 'DEFINE C-CURU OSNOWAIT POPSCR'
  169. 'DEFINE C-PADPLUS OSNOWAIT SWAPSCR'
  170.  
  171. /* We redefine C-K to a smarter duplication function.                 */
  172. 'DEFINE C-K MC /dup/tab'
  173.  
  174. /* We define tools to search through command history.                 */
  175. C_F = '06'x; C_R = '12'x; global = global 'item'; item = ''
  176. '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";',
  177.            '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;',
  178.            'if currLine=0 then currLine=prevLine.0;end;if pos(item,prevLine.currLine) \= 0 then line=prevLine.currLine;currOfs=length(line);xOfs=0;end'
  179. 'DEFINE C-F OSN RX if item\="" then do; oldCur=currLine;currLine = currLine-1;if currLine = 0 then currLine=prevLine.0;',
  180.            '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'
  181.  
  182. /* Here, we redefine help messages in French...                       */
  183. defHelp = "Utilisez la command DEFINE pour (re)définir le rôle des touches"nl||,
  184.           "du clavier."nl||nl||,
  185.           "SYNTAXE:    DEF touche [valeur]"nl||,
  186.           "         DEFINE touche [valeur]"nl||nl||,
  187.           "          touche  Spécifie le nom de la touche à définir."nl||,
  188.           "          valeur  Valeur affectée à la touche. Ce peut être une"nl||,
  189.           "                  commande interne, MC xxx, OSNowait yyy ou TEXT zzz."nl||nl||,
  190.           "Exemples:"nl||,
  191.           "          DEF F12 TEXT dir /w"nl||,
  192.           "       DEFINE F3  OSNOWAIT exit"nl||,
  193.           "          DEF F12"
  194. aliasHelp = "Utilisez la commande ALIAS pour afficher, définir ou"nl||,
  195.             "supprimer un alias."nl||nl||,
  196.             "SYNTAXE: ALIAS [LIST|alias=[chaîne]|@fichier]"nl||nl||,
  197.             "          LIST     Affiche la liste des alias en cours."nl||,
  198.             "          alias    Spécifie le nom de l'alias."nl||,
  199.             "          chaîne   Valeur alphanumérique affectée à l'alias."nl||,
  200.             "          fichier  Nom d'un fichier contenant un ensemble de"nl||,
  201.             "                   définitions d'alias."nl||nl||,
  202.             "Dans la définition d'un alias, %* correspond aux paramètres"nl||,
  203.             "passés sur la ligne de commande."
  204. ruleHelp = "Utilisez la commande RULE pour afficher, définir ou"nl||,
  205.            "supprimer une règle."nl||nl||,
  206.            "SYNTAXE: RULE [LIST|règle=[chaîne]|@fichier]"nl||nl||,
  207.            "          LIST     Affiche la liste des règles en cours."nl||,
  208.            "          règle    Spécifie le nom de la règle."nl||,
  209.            "          chaîne   Valeur alphanumérique affectée à la règle."nl||,
  210.            "          fichier  Nom d'un fichier contenant un ensemble de"nl||,
  211.            "                   définitions de règles."nl||nl||,
  212.            "Dans la définition d'une règle, %*, %c, %d, %e, %f, %l, %o et"nl||
  213.            "%x dénotent le type des paramètres."
  214. cmdHelp = "Utilisez la commande CMDSHL pour augmenter les capacités de"nl||,
  215.           "votre interpréteur de commande."nl||nl||,
  216.           "SYNTAXE: CMDSHL [/I|/O] [/P profile] [/C cmd|/K cmd]"nl||nl||,
  217.           "          /I    Sélecte le mode Insertion par défaut."nl||,
  218.           "          /O    Sélecte le mode surfrappe par défaut."nl||,
  219.           "          /P    Utilise le fichier profile spécifié."nl||,
  220.           "          /C    Exécute la commande cmd et met fin à l'exécution"nl||,
  221.           "                de CMDSHL."nl||,
  222.           "          /K    Exécute la commande cmd sans mettre fin à l'exécution"nl||,
  223.           "                de CMDSHL."nl||nl||,
  224.           "Par défaut, le mode Insertion est actif et le fichier PROFILE.SHL"nl||,
  225.           "est utilisé comme profile s'il existe sur le chemin spécifié par"nl||,
  226.           "la variable d'environnement DPATH."
  227. cdHelp = "Tapez CD -        Pour retourner au répertoire précédent."nl||,
  228.          "Tapez CD s1 s2    Pour remplacer s1 par s2 dans le répertoire en cours."
  229. quitHelp = "Utilisez la commande QUIT pour quitter CMDSHL."nl||nl||,
  230.            "SYNTAXE: QUIT"
  231.  
  232.  
  233. /* useful aliases... from my point of view :-) */
  234. 'ALIAS rlogin=cls ^& ckermit ^& UTIL\telnet %1.unice.fr ^& cd -'
  235. 'ALIAS xrn=e:\local\yarn ^& yarn.exe ^& cd -'
  236. 'ALIAS open=rx xline = "%*"; if xline = "" then xline = directory(); else xline = findcommand(); call SysOpenObject xline,"DEFAULT",1; call SysOpenObject xline,"DEFAULT",1'
  237. 'ALIAS tc=java TCTypeCheck %*'
  238. 'ALIAS dir=sdir %*'
  239. 'ALIAS build=nrc -nocompile %1 ^& javac -d . %1.java ^& del %1.java'
  240. '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)'
  241. 'ALIAS loop=rx do %*'
  242. 'ALIAS qd=query date'
  243. 'ALIAS qt=query time'
  244.  
  245. /* useful rule... from my point of view :-) */
  246. 'RULE WHENCE=%f %e'
  247.