getting ^L to clear the screen?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

getting ^L to clear the screen?

Daniel Dickman-2
Does anyone know how to bind ^L to clear the screen in a default 3.9
installation? I'd prefer to not have to change to bash if I don't have to...

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Christian Weisgerber
Daniel Dickman <[hidden email]> wrote:

> Does anyone know how to bind ^L to clear the screen in a default 3.9
> installation?

You can't, at the shell prompt.  ksh can't do that.
Run clear(1).

--
Christian "naddy" Weisgerber                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Claus Assmann-5
On Sun, May 28, 2006, Christian Weisgerber wrote:
> Daniel Dickman <[hidden email]> wrote:

> > Does anyone know how to bind ^L to clear the screen in a default 3.9
> > installation?

> You can't, at the shell prompt.  ksh can't do that.

What's wrong with

        alias =clear

It works for me (OpenBSD 3.8, /bin/ksh).

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Paul de Weerd
In reply to this post by Daniel Dickman-2
On Sun, May 28, 2006 at 05:52:49PM -0400, Daniel Dickman wrote:
| Does anyone know how to bind ^L to clear the screen in a default 3.9
| installation? I'd prefer to not have to change to bash if I don't have
to...

Please note that when using emacs editing mode (I think this is the
default mode, unless you set VISUAL=vi or use `set -o vi` explicitly)
and when in command-mode in the vi editing mode, ^L is already bound
to redraw. This will redraw your current input line. See ksh(1) for
more info (search for \^L). But anyway...

What is wrong with using clear ? You could alias it to l or L or
create a function of the same name in your shell configuration file
(.profile) to have the same effect with the same number of keypresses.

Using an alias :
        alias l="/usr/bin/tput clear"
        alias L="/usr/bin/tput clear"

Using a function :
        l() { /usr/bin/tput clear; }
        L() { /usr/bin/tput clear; }

You could also try this in your shell :

        trap '/usr/bin/tput clear' 2

And press ^C. Note that this has some rather unfortunate side-effects
(apart from being silly), but it does does clear the screen on ^C.

A last option would be to send a patch for ksh that adds a clearscreen
command to bind to. Send it here and it'll probably get more attention
from developers. This is left as an excercise to you ;)

Good luck clearing your screen !

Paul 'WEiRD' de Weerd

--
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/

[demime 1.01d removed an attachment of type application/pgp-signature]

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Christian Weisgerber
Paul de Weerd <[hidden email]> wrote:

> A last option would be to send a patch for ksh that adds a clearscreen
> command to bind to. Send it here and it'll probably get more attention
> from developers. This is left as an excercise to you ;)

This would require linking ksh to libtermcap, growing it substantially.
The genius of ksh's line editor is its simplicity: it just uses carriage
return to overwrite the line, it doesn't do full cursor control.

--
Christian "naddy" Weisgerber                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Christian Weisgerber
In reply to this post by Claus Assmann-5
Claus Assmann <[hidden email]> wrote:

> What's wrong with
>
> alias =clear
>
> It works for me (OpenBSD 3.8, /bin/ksh).

How?  You enter ^V^L<return>?  That's probably not what the original
poster asked for, given the mention of bash.

--
Christian "naddy" Weisgerber                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Claus Assmann-5
On Mon, May 29, 2006, Christian Weisgerber wrote:
> Claus Assmann  wrote:

> > What's wrong with

> > alias =clear

> > It works for me (OpenBSD 3.8, /bin/ksh).

> How?  You enter ^V^L<return>?  That's probably not what the original

The alias is in .kshrc. I just it CNTL-L on the command prompt and
the screen will be cleared. Just try it. If it doesn't work for you
(in ksh) then we must have some different settings for it.

> poster asked for, given the mention of bash.

Sorry, my reply was prompted by to your statement:

! You can't, at the shell prompt.  ksh can't do that.

It works under SunOS 5.8 et.al. too.

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

John Wright-6
In reply to this post by Daniel Dickman-2
On Sun, May 28, 2006 at 05:52:49PM -0400, Daniel Dickman wrote:
> Does anyone know how to bind ^L to clear the screen in a default 3.9
> installation? I'd prefer to not have to change to bash if I don't have to...

Just for a bit of variety (since you've had lots of replies) I use this:

   bind -m ^L=clear^M

Which types c l e a r RETURN where my cursor is.

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Han Boetes
John Wright wrote:
> On Sun, May 28, 2006 at 05:52:49PM -0400, Daniel Dickman wrote:
> > Does anyone know how to bind ^L to clear the screen in a default 3.9
> > installation? I'd prefer to not have to change to bash if I don't have to...
>
> Just for a bit of variety (since you've had lots of replies) I use this:
>
>    bind -m ^L=clear^M
>
> Which types c l e a r RETURN where my cursor is.

Shells like zsh and bash also clear the screen while you are
typing a line. So your solution works only fine at the start of a
line. And adding a c-g or c-c won't help since it also interupts
the macro.



# Han

Reply | Threaded
Open this post in threaded view
|

Re: getting ^L to clear the screen?

Bertrand Janin
Han Boetes wrote :
> John Wright wrote:
> >    bind -m ^L=clear^M
> >
> > Which types c l e a r RETURN where my cursor is.
>
> Shells like zsh and bash also clear the screen while you are
> typing a line. So your solution works only fine at the start of a
> line. And adding a c-g or c-c won't help since it also interupts
> the macro.

I tried to do something like that :

    bind -m ^L=^Uclear^M^Y

If you do each steps one by one, it works: remove the line, use clear
and put the line back on the screen. For some reason once it's in the
bind, it doesn't 'use' the ^Y at the end. In fact if you ^Y by hand
after this user-defined ^L, it 'pastes' the non-empty line that was
there before the clear.


--
Bertrand