on *:close:@c:{
  _unload
}
alias console {
  if ($window(@c)) window -c @c
  window -daCek0w1 +ts @c -1 -1 400 300
  titlebar @c - /console
  if (%lastused) _load %lastused
}

; One-liners
alias -l c { aline -ip @c $1- | aline -ip @c $crlf } 
alias -l _file return $qt($hget(console,filepath))
alias -l _author return $hget(console,author)
; End of

; Core functions
alias _load {
  if ($window(@c)) {
    var %file = $qt($noqt($1-))
    if ($isfile(%file)) {
      if ($hget(console)) hfree console 
      hmake console
      hload console %file
      hadd console filepath $longfn($noqt(%file))
      _save
      c * Successfully loaded $nopath($noqt(%file)) 
    }
    else c * Error, invalid file ( $+ $nopath($noqt(%file)) $+ )
  }
}
alias _unload {
  if ($window(@c)) {
    if ($hget(console)) {
      hsave console $_file
      set %lastused $_file
      hfree console 
      c * Successfully unloaded file
    }
    else c * Error, no file loaded
  }
}
alias _save {
  if ($window(@c)) {
    if ($hget(console)) {
      if ($_file) { hsave console $v1 | c * Successfully saved to $nopath($_file) }
    }
  }
}
alias _ls {
  noop $finddir($qt($mircdir),*,0,1,aline @c $nopath($1-)) | noop $findfile($qt($mircdir),*,0,1,aline @c $nopath($1-))
}
alias _list {
  if ($1 === -f) {
    var %n = 1,%files
    while ($findfile($qt($mircdir),*.hsh,%n,1)) {
      var %file = $v1,%files = %files $nopath(%file)
      inc %n
    }
    c Possible files: %files
  }
}
; End of
