set term off
set linesize 114
set pages 99
set tab off
set trimout on
set trimspool on

define mysid=unknown
define myserial=unknown

var sid number
var serial# number
var tracefile varchar2(200)

col username for a12
col mysid head sid format a6 new_value mysid
col myserial for 999999 new_value myserial
col host_command new_value host_command
col spid for 999999
col host_name for a25
col segment_name format a30

def _editor = gvim

begin
	:sid := nvl(:sid,sys_context('userenv','sid'));
   :serial# := dbms_debug_jdwp.current_session_serial;
end;
/
-- Also need SID as & variable to use in HOST command later:
select to_char(:sid) as mysid, to_char(:serial#) as myserial from dual;

-- Detect OS, use "TITLE" command to set Window display title if Windows, else echo (actual there is an esape sequence for PuTTY that might work here)
select 'echo Connected as: ' as host_command
from   dual
where  sys_context('userenv','terminal') like 'pts/%'
or     sys_context('userenv','terminal') like 'tty%';

select 'title' as host_command
from   dual
where  sys_context('userenv','host') like '%\%';

host &host_command &_user@&_connect_identifier [session &mysid, serial# &myserial]
undef myserial
undef mysid
undef host_command

col name format a30
col column_name format a30
col name_col_plus_show_param format a30
col value_col_plus_show_param format a80
col line/col format a10
col error format a99

set term off

set lines 130
set pages 999
set feed off
set pause >>>
set pause off
set ver off
set trimspool on
set echo off
set serverout on size 1000000 format word
set tab off
set autoprint off
cl buff
set term on

set feed on feed 1 tab off autoprint on

prompt debug: "login.sql"
prompt

