Friday Sep 28, 2012

sqlplus: Running "set lines" and "set pagesize" automatially

This is a followup to my previous entry.

Using the full tty real estate with sqlplus (INOUE Katsumi @ Tokyo)
'rlwrap' is widely used for adding 'sqlplus' the history function and command line editing.
Here's another but again kludgy implementation. First this is the alias.
alias sqlplus="rlwrap -z ~/sqlplus.filter sqlplus"

And this is the file content.
#!/usr/bin/env perl

use lib ($ENV{RLWRAP_FILTERDIR} or ".");
use RlwrapFilter;
use POSIX qw(:signal_h);
use strict;

my $filter = new RlwrapFilter;
$filter -> prompt_handler(\&prompt);

sigprocmask(SIG_UNBLOCK, POSIX::SigSet->new(28));
$SIG{WINCH} = 'winchHandler';

$filter -> run;

sub winchHandler {
  $filter -> input_handler(\&input);
  sigprocmask(SIG_UNBLOCK, POSIX::SigSet->new(28));
  $SIG{WINCH} = 'winchHandler';
  $filter -> run;
}

sub input {
  $filter -> input_handler(undef);
  return `resize |sed -n "1s/COLUMNS=/set linesize /p;2s/LINES=/set pagesize /p"` . $_;
}

sub prompt {
  if ($_ =~ "SQL> ") {
    $filter -> input_handler(\&input);
    $filter -> prompt_handler(undef);
  }
  return $_;
}


I hope I can compare these 2 implementations after testing more and getting some feedbacks.


Wednesday Sep 19, 2012

Using the full tty real estate with sqlplus

I believe 'rlwrap' is widely used for adding 'sqlplus' the history function and command line editing.
'rlwrap' has other functions and here's my kludgy alias to force sqlplus to use the full real estate of your
tty. Be it PuTTy session from Windows or Linux gnome terminal.

$ declare -f sqlplus
sqlplus ()
{
    PRE_TEXT=$(resize |sed -n "1s/COLUMNS=/set linesize /p;2s/LINES=/set pagesize /p"|while read line; do printf "%s \ " "$line";done);
    if [ -z "$1" ]; then
        rlwrap -m -P "$PRE_TEXT" sqlplus /nolog;
    else
        if ! echo $1 | grep '^-' > /dev/null; then
            rlwrap -m -P "$PRE_TEXT connect $*" sqlplus /nolog;
        else
            command sqlplus $*;
        fi;
    fi
} 




About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« September 2012 »
SunMonTueWedThuFriSat
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20
21
22
23
24
25
26
27
29
30
      
Today