Skip to content

Instantly share code, notes, and snippets.

@chrisgward
Created January 4, 2015 19:38
Show Gist options
  • Save chrisgward/1afd6abf3b8a177abfe9 to your computer and use it in GitHub Desktop.
Save chrisgward/1afd6abf3b8a177abfe9 to your computer and use it in GitHub Desktop.
bind pub n&- ~ stcl
proc stcl {nick host hand chan arg} {
set ctx [getctx]
set lines 5
set prefix 1
set first [lindex [split $arg " "] 0]
set skipempty 1
if {$first == "-q"} {
set arg [string range $arg 3 end]
set lines 0
} elseif {$first == "-v"} {
set arg [string range $arg 3 end]
set lines -1
} elseif {$first == "-vv"} {
set arg [string range $arg 4 end]
set lines -1
set skipempty 0
}
set ctx [getctx]
global stclerror
set stclerror 1
catch {global response; set response [eval $arg]; global stclerror; set stclerror 0} result
if {$stclerror} {
global errorInfo
set result $errorInfo
} else {
global response
set result $response
}
setctx $ctx
if {$result == ""} { putchan $chan "~ = <null>" }
set slines [split $result \n]
set printed 0
for {set i 0} {$i < [llength $slines] && $lines != 0 && ($printed < 5 || [llength $slines] == 6 || $lines == -1)} {incr i} {
set sline [lindex $slines $i]
if {[string trim $sline] != "" || $skipempty == 0} {
putchan $chan "~ = [ansi $sline]"
incr printed
}
}
if {$i != [llength $slines] && $lines != 0} {
putchan $chan "~ [expr [llength $slines] - $printed - 1] additional line(s) skipped"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment