alias ge echo $G $*

alias wrapon {^set continued_line $box.echo()$repeat(${[$0]-1}  )$(cl)}
alias wrapoff {^set continued_line $repeat(4  )}
alias asave {
  ^local vars
  fe ($savec) ii {
    $ii}
  @ fexist($a.varsave) != -1 ? unlink($a.varsave) :
  @ vars = open($a.varsave W T)
  fe ($savevars) ii {
    @ write($vars $(ii): $($ii))}
  @ close($vars)
  svt
  ge saved argon settings.}

alias loadvars if (fexist($a.varsave) != -1) {
  ^local vars,read
  @ vars = open($a.varsave R T)
  while (!eof($vars)) {
    @ read = read($vars)
    if (read) {@ $before(-1 : $leftw(1 $read)) = rightw(${#read-1} $read)}
  }
  @ close($vars)}
#load|savearray filename arrayname echotext
alias loadarray if ([$*]) {
	@delarray($1)
	^local fd $open($0 R)
	$read($fd)
	while (!eof($fd)) {
		^local bb $read($fd)
		if (bb) {
 			@setitem($1 $numitems($1) $bb)}}
	@close($fd)}
alias savearray if ([$*]) {
	@unlink($0)
	^local fd $open($0 W)
	@write($fd $2-)
	for (@xx=0, xx<numitems($1), @xx++) {
		@write($fd $getitem($1 $xx))}
	@close($fd)}
alias cre {
  ge BitchX: Rehashing .bitchxrc...
  ^timer -dump all
  ^dump all
  ^load ~/.bitchxrc}

alias remword {
  @ $0 = remw($1 $($0))}

# this is from the epic scriptpack (props to hop for this)
# i rewrote it to use faster arrays.
alias less_pipe {
	@ delarray(lessline)
	if ([$1]) {
		^on ^exec "$0 *" {
			@ setitem(lessline $numitems(lessline) $1-)}
		^on ^exec_error "$0 *" {
			ge $1-}
		^on ^exec_exit "$0 *" {
			on exec -"$0 *"
			on exec_error -"$0 *"
			on exec_exit -"$0 *"
			less_array lessline 0 $numitems(lessline)}
		exec -name $*}}
alias less_array {
	^local line $1
	^local cra 0
	^local rows $winsize()
        ^local lban $3
	while ((line < [$2]) && (cra < rows)) {
		echo $lban $getitem($0 $line)
        	@ cra += numlines($stripansicodes($getitem($0 $line)))
		@ line++}
	if (cra >= rows) {
		@ aaa.array_name = [$0]
		@ aaa.next_line = line
		@ aaa.final_line = [$2]
                @ aaa.banner = [$3]
		input_char "-> any key more more, q to quit. " if ([$0] != [q]) {
			^less_array $aaa.array_name $aaa.next_line $aaa.final_line $aaa.banner} else {
			if (readinglog) {@readinglog=0;^hook dellog}}} else {
		if (readinglog) {@readinglog=0;^hook dellog}}}

alias redirect redir
 
alias redir {
  ^stack push on redirect
  ^on ^redirect * {
    msg $0 ${flag(pubansi) ? [$1-] : stripansicodes($1-)}}
  wait for {//redirect $*}
  ^stack pop on redirect}

alias setflag if (after(1 , $*)) {
  ^local arg.
  @ arg.0 = before(1 , $*)
  @ arg.1 = after(1 , $before(2 , $*))
  @ arg.2 = after(2 , $*)
  if (arg.2) {
    @ $arg.0 = arg.2
    ge $arg.1 is now set: $($arg.0)} elsif (match($($arg.0) $not.yes $not.no)) {
      @ $arg.0 = not($($arg.0))
      ge $arg.1 is now set: $($arg.0)} else {
        ge $arg.1 is currently set: $($arg.0)}}

loadvars
fixecho
reinitstat
