how to start in "overwrite-mode"

View: New views
4 Messages — Rating Filter:   Alert me  

how to start in "overwrite-mode"

by Jim Lawson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi bug-bash,

I have a user we're trying to encourage to migrate from tcsh to bash,
who is used to his shell starting up in overwrite mode (as opposed to
the default Insert mode.)

Long story short, while I can easily bind a key to the "overwrite-mode"
readline function, I can't figure out how to make bind start up that way
as I can't find an "overwrite" readline variable which I can manipulate.
 And the user doesn't want to hit "Ins" every time he starts a shell.

Anyone know how to do this?

--
Jim Lawson
Systems Architecture & Administration
Enterprise Technology Services
University of Vermont
Burlington, VT USA



Re: how to start in "overwrite-mode"

by Bugzilla from dave@evilpettingzoo.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 27, 2009 at 16:29, Jim Lawson <jtl+bug-bash@...> wrote:

> I have a user we're trying to encourage to migrate from tcsh to bash,
> who is used to his shell starting up in overwrite mode (as opposed to
> the default Insert mode.)
>
> Long story short, while I can easily bind a key to the "overwrite-mode"
> readline function, I can't figure out how to make bind start up that way
> as I can't find an "overwrite" readline variable which I can manipulate.
>  And the user doesn't want to hit "Ins" every time he starts a shell.
>
> Anyone know how to do this?

With the caveats that this is an awful solution, and it requires
that the user be willing to commit to one or two terminal types
(say, Xterm), I found a horrible way to do this.

The control characters below are literal in the real files.
Assuming the insert key on your keyboard is ^[[2~ :

Add to .Xdefaults: XTerm*answerbackString: ^[[2~
Add to .bashrc (and .profile if it doesn't source .bashrc):
    bind '"^[[2~": overwrite-mode'
    PROMPT_COMMAND='echo -n ^E'

This causes xterm to respond by simulating a pressing
of the insert key before each PS1 prompt, putting that
line into overwrite. If the user drops down to a PS2, etc.
prompt, that line will be in insert mode. I didn't solve that;
putting a ^E into PS* didn't work for some reason. (Why?)

Dave



Parent Message unknown Re: how to start in "overwrite-mode"

by Stephane Chazelas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009-10-28, 20:28(-04), Dave Rutherford:
[...]
> Add to .Xdefaults: XTerm*answerbackString: ^[[2~
> Add to .bashrc (and .profile if it doesn't source .bashrc):
>     bind '"^[[2~": overwrite-mode'
>     PROMPT_COMMAND='echo -n ^E'
[...]

Along those lines, you could use the TIOCSTI ioctl. That would
be system dependant instead of terminal dependant. Like sti.c:

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int i;
  char *c;

  if (!isatty(0))
    return 0;

  for (i = 1; i < argc; i++) {
    if (i > 1 && ioctl(0, TIOCSTI, " ") == -1)
    {
      perror("ioctl");
      return 1;
    }
    for (c = argv[i]; *c; c++) {
      if (ioctl(0, TIOCSTI, c) == -1)
      {
        perror("ioctl");
        return 1;
      }
    }
  }
  return 0;
}

And

PROMPT_COMMAND="sti \$'\05'"

> If the user drops down to a PS2, etc.
> prompt, that line will be in insert mode.
[...]

Same problem here.

--
Stéphane

Re: how to start in "overwrite-mode"

by Stephane Chazelas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009-10-29, 07:23(+00), Stephane CHAZELAS:

> 2009-10-28, 20:28(-04), Dave Rutherford:
> [...]
>> Add to .Xdefaults: XTerm*answerbackString: ^[[2~
>> Add to .bashrc (and .profile if it doesn't source .bashrc):
>>     bind '"^[[2~": overwrite-mode'
>>     PROMPT_COMMAND='echo -n ^E'
> [...]
>
> Along those lines, you could use the TIOCSTI ioctl. That would
> be system dependant instead of terminal dependant. Like sti.c:
[...]
> PROMPT_COMMAND="sti \$'\05'"

Sorry, that should have been

PROMPT_COMMAND="sti \$'\e[2~'"

Assuming ^[[2~ is bound to overwrite-mode.

--
Stéphane