home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / editor / alpha513.cpt / shell.tcl < prev    next >
Text File  |  1992-10-22  |  3KB  |  125 lines

  1.  
  2. proc initShell {} {
  3.     insertText "Welcome to Alpha's Tcl shell."
  4.     shellPrompt [lindex [winNames] 0]
  5. }
  6.  
  7. # Output the prompt. We want the window name because some of the commands
  8. # we evaluate (such as 'edit') open a new window, and we want the insertion
  9. # to be done in the shell window.
  10. proc shellPrompt {winName} {
  11.     regexp "(\[^:\]*):$" [pwd] crDum crDir
  12.     insertText -w $winName "\r" $crDir "> "
  13. }
  14.  
  15.  
  16. # Called at all carriage returns.
  17. proc carriageReturn {} {
  18.     global mode
  19.     set indentString ""
  20.     deleteText [getPos] [selEnd]
  21.     if {[getVar indentOnCR]} {
  22.         set pos [getPos]
  23.         set text [getText [lineStart $pos] $pos]
  24.         for {set i 0; set len [string length $text]} {$i <= $len} {incr i} {
  25.             set c [string index $text $i]
  26.             if {($c != "\t") && ($c != "\ ")} {
  27.                 set indentString [string range $text 0 [expr $i-1]]
  28.                 break
  29.             }
  30.         }
  31.     }
  32.     insertText "\r" $indentString
  33. }
  34.  
  35.  
  36. proc tclCarriageReturn {} {
  37.     global mode
  38.     global _text
  39.     global _returnText
  40.     set pos [getPos]
  41.     set ind [string first ">" [getText [lineStart $pos] $pos]]
  42.     if {$ind < 0} {
  43.         carriageReturn
  44.         return
  45.     }
  46.     set lStart [expr [lineStart $pos]+$ind+2]
  47.     endOfLine
  48.     set _text [getText $lStart [getPos]]
  49.     set fileName [lindex [winNames] 0]
  50.     if {[getPos] != [maxPos]} {
  51.         goto [maxPos]
  52.         insertText -w $fileName $_text
  53.     }
  54.     if {[string first "mpw" $fileName] != -1} {
  55.         set _returnText [dosc -n ToolServer -s $_text]
  56.         insertText "\r" $_returnText
  57.         mpwPrompt
  58.     } else {
  59.         uplevel #0 {catch $_text _returnText}
  60.         if {[string length $_returnText]} {
  61.             insertText -w $fileName "\r" $_returnText
  62.         } 
  63.         shellPrompt $fileName
  64.     }
  65.     unset _text
  66.     unset _returnText
  67. }
  68. bind '\r' carriageReturn
  69. bind '\r' tclCarriageReturn "Csh"
  70. bind '\r' tclCarriageReturn "MPW"
  71.  
  72. proc startMPW {} {
  73.     insertText "Welcome to Alpha's MPW shell (using ToolServer via AppleEvents)."
  74.     launch "External:Babel:Tools:ToolServer"
  75.     bind '\r' tclCarriageReturn "MPW"
  76.     carriageReturn
  77.     mpwPrompt
  78. }
  79. proc mpwPrompt {} {
  80.     insertText "mpw> "
  81. }
  82.  
  83. proc setMPWMode {} {
  84.     changeMode "MPW"
  85. }
  86.  
  87. #    tclCarriageReturn
  88.  
  89.  
  90.  
  91. #=============================================================================
  92. #    Shell Aliases
  93. #=============================================================================
  94. proc l {args} {
  95.     eval [concat "ls -F" $args]}
  96.  
  97. proc ll {args} {
  98.     eval [concat "ls -l" $args]}
  99.  
  100.  
  101. proc grep {pat args} {
  102.     insertText "\r"
  103.     set pat *$pat*
  104.     set args [glob -nocomplain $args]
  105.     foreach file $args {
  106.         set id [open $file]
  107.         while {[gets $id string] != "-1"} {
  108.             if {[string match $pat $string] == 1} {
  109.                 insertText $file: $string "\r"
  110.             }
  111.         }
  112.         close $id
  113.     }
  114. }
  115.  
  116.  
  117. proc ts script {
  118.     return [dosc -n ToolServer -s $script]
  119. }
  120.  
  121. proc tl {} {
  122.     launch "External:Babel:Tools:ToolServer"
  123. }
  124.  
  125.