# Type /dos to run this # Whee. kaddhelp dos "Opens up a 'shell' prompt." /dos "Shell Prompt" set shellver 1.2 alias dos { /query .Shell. update_dos window restore .shell. window focus .Shell. window clear .shell. echo "SHELLv$shellver by kano\n " complete } myalias privmsg { if {[string tolower [lindex [args] 0]] == ".shell." && [string tolower [query]] == ".shell."} { do_shell [string range [string trim [raw_args]] [expr [string length [lindex [args] 0]] +1] end] } } set doing_command "" proc do_shell string { global doing_command set string [split $string] set cmd [join [lindex $string 0]] echo "% [join $string]" query .shell. input set_text "" switch -- $cmd { dir - ls { if {[lindex $string 1] == ""} {set glob *} {set glob [lindex $string 1]} set oldcd [pwd] cd [file join [pwd] [get_cookie shellpwd] [file dirname $glob]] set x [lsort [glob -nocomplain -- [file join [get_cookie shelldir] $glob]]] cd $oldcd set len 0 foreach i $x { set strlen [string length $i] if {$strlen > $len} {set len $strlen} } if {$len > 72} {set len 72} set this_line "" foreach i $x { if {[expr [string length $this_line] + [string length $i] +1] > 72 && $this_line != ""} { echo $this_line query .shell. set this_line "" } { if {$this_line == ""} {set space ""} {set space " "} append this_line "$space[format %-${len}s $i]" } } if {$this_line != ""} {echo $this_line} } cd { if {[lindex $string 1] == ""} {set pwd [pwd]} {set pwd [file join [pwd] [get_cookie shellpwd] [lindex $string 1]]} if ![file isdir $pwd] { echo "No such directory" } { set end "" foreach a [file split $pwd] { if {$a == ".."} { set end [lrange $end 0 [expr [llength $end] -2]] } elseif {$a != "."} { lappend end $a } } catch "file join $end" pwd set_cookie shellpwd $pwd echo "Now in $pwd" update_dos } } del - delete - rm { set file [glob -nocomplain -- [file join [pwd] [get_cookie shellpwd] [lindex $string 1]]] if {$file == ""} { echo "No matches" } { foreach i $file { file delete $i } echo "Deleted [llength $file] files" } } ren - rename - move - mv { set file [glob -nocomplain -- [file join [pwd] [get_cookie shellpwd] [lindex $string 1]]] set dest [glob -nocomplain -- [file join [pwd] [get_cookie shellpwd] [lindex $string 2]]] if {$file == ""} { echo "No matches for [lindex $string 1]" } elseif {$dest == ""} { echo "No matches for [lindex $string 2]" } elseif {[llength $dest] > 1} { echo "Ambiguous destination $dest" } elseif {[llength $file] > 1 && ![file isdir [set dest [lindex $dest 0]]]} { echo "$dest: destination is not directory" } { set copied 0 foreach i $file { if [catch [list file rename $i [file join $dest [file tail $i]]]] { echo "Error moving file $i" } {incr copied} } echo "Moved $copied files" } } xcopy - copy - cp { set file [glob -nocomplain -- [lindex $string 1]] set dest [glob -nocomplain -- [lindex $string 2]] if {$file == ""} { echo "No matches for $file" } elseif {$dest == ""} { echo "No matches for $dest" } elseif {[llength $dest] > 1} { echo "Ambiguous destination $dest" } elseif {[llength $file] > 1 && ![file isdir [set dest [lindex $dest 0]]]} { echo "$dest: destination is not directory" } { set copied 0 foreach i $file { if [catch [list file copy $i [file join $dest [file tail $i]]]] { echo "Error copying file $i" } {incr copied} } echo "Copied $copied files" } } mkdir { if [catch [list file mkdir [lindex [args] 1]] x] { echo "error: $x" } } touch { set glob [glob -nocomplain -- [lindex [args] 1]] if {$glob == ""} { close [open [lindex [args] 1] w] } { echo "File already exists" } } run - open { if {[set err1 [catch [list lrange [join $string] 1 end] parms]] || [set err2 [catch [list lindex [join $string] 0] command]]} { if $err1 { echo "error: $err1" } if $err2 { echo "error: $err2" } } { if [catch [list FALC_shell -p $parms $command] err] { echo "error: $err" } } } exit {window close query .shell.;catch {close stdin};catch {close stdout}} default { catch {close stdin} catch {close stdout} if ![catch [list open |[join $string]] x] { fconfigure $x -blocking 0 -buffering line fileevent $x readable [list show_dos $x] set doing_cmd $x } { echo "error: $x" } } } complete } proc show_dos x { if [eof $x] {close $x} echo [gets $x] query .shell. } proc update_dos args { window set_title "DOS Console - [file join [pwd] [get_cookie shellpwd]]" query .shell. } on unload {catch [list close \$doing_cmd]}