Re: Does sftp(1) support editline(3)?

2025-12-19 Thread Dave Polaschek
> const char editor[2];

If you get an editor string that is longer than 1 character (plus trailing 0 to 
terminate the string), do you know what’s getting clobbered? Something almost 
certainly is.

-DaveP

On Fri, Dec 19, 2025, at 07:30, Walter Alejandro Iglesias wrote:

> (src/usr.bin/ssh/sftp.c)
> -
> const char editor[2];
>
>   if (!batchmode && isatty(STDIN_FILENO)) {
>
>   [...]
>
>   if (el_get(el, EL_EDITOR, editor) == '0')
>   printf("Editor: %s\n", editor);
>
>   if (strncmp(editor, "vi", 2) == 0)
>   el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
>   }
>
> 
>
> Am I using el_get() in a wrong way?
>
>
> -- 
> Walter



Re: Does sftp(1) support editline(3)?

2025-12-19 Thread Walter Alejandro Iglesias
On Fri, Dec 19, 2025 at 03:30:39PM +0100, Walter Alejandro Iglesias wrote:
> (src/usr.bin/ssh/sftp.c)
> -
> const char editor[2];
> 
>   if (!batchmode && isatty(STDIN_FILENO)) {
> 
>   [...]
> 
>   if (el_get(el, EL_EDITOR, editor) == '0')
>   printf("Editor: %s\n", editor);
> 
>   if (strncmp(editor, "vi", 2) == 0)
>   el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
>   }
> 
> 
> 


The printf() command is for testing.


-- 
Walter



Re: Does sftp(1) support editline(3)?

2025-12-19 Thread Walter Alejandro Iglesias
On Thu, Dec 18, 2025 at 03:50:39PM -, Stuart Henderson wrote:
> On 2025-12-18, Walter Alejandro Iglesias  wrote:
> > On Thu, Dec 18, 2025 at 02:16:26PM -, Stuart Henderson wrote:
> >> On 2025-12-18, Walter Alejandro Iglesias  wrote:
> >> > I found the following in sftp(1) source code:
> >> >
> >> >   $ grep editline /usr/src/usr.bin/ssh/*
> >> >   sftp.c: fatal("Couldn't initialise editline");
> >> >   sftp.c: fatal("Couldn't initialise editline history");
> >> >
> >> > I use this line in ~/.editrc:
> >> >
> >> >   bind -v
> >> >
> >> > That gives me vi-like keybindings in many applications.  But it doesn't
> >> > work with sftp(1).
> >> 
> >> sftp does use editline, and it does read .editrc.
> >> 
> >> bind -v does do something in sftp (you'll see a behaviour change if you
> >> remove it) but it's not normal vi-like handling..
> >
> > What I see when I remove 'bind -v' from ~/.editrc is that emacs-like
> > bindings work.  So, the only effect of 'bind -v' in sftp(1) is to
> > deactivate emacs-like bindings.
> 
> editline(7) says:
> 
>  The program can switch the default to emacs mode by using the
>el_set(3) or el_parse(3) functions, and the user can switch to emacs
>mode either in the editrc(5) configuration file or interactively with
>the ed-command editor command, in all three cases executing the bind
>-e builtin command.
> 
> sftp switches the default using 'el_set(el, EL_EDITOR, "emacs")', but
> I don't see anything in editline(7) that suggests you can get back from
> there to vi mode.
> 
> you can at least automatically fix the key bindings like this:
> 
> $ cat .editrc
> bind -v
> sftp:bind -e
> 
> 

I noticed that adding the following line to the bindings in
'src/usr.bin/ssh/sftp.c' to makes vi command mode work:

  el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);

But I couldn't figured out so far how to add a conditional to apply that
binding only in vi mode.  The following does not work:

(src/usr.bin/ssh/sftp.c)
-
const char editor[2];

if (!batchmode && isatty(STDIN_FILENO)) {

[...]

if (el_get(el, EL_EDITOR, editor) == '0')
printf("Editor: %s\n", editor);

if (strncmp(editor, "vi", 2) == 0)
el_set(el, EL_BIND, "^[", "vi-command-mode", NULL);
}



Am I using el_get() in a wrong way?


-- 
Walter



Re: Does sftp(1) support editline(3)?

2025-12-18 Thread Walter Alejandro Iglesias
On Thu, Dec 18, 2025 at 03:50:39PM -, Stuart Henderson wrote:
> On 2025-12-18, Walter Alejandro Iglesias  wrote:
> > On Thu, Dec 18, 2025 at 02:16:26PM -, Stuart Henderson wrote:
> >> On 2025-12-18, Walter Alejandro Iglesias  wrote:
> >> > I found the following in sftp(1) source code:
> >> >
> >> >   $ grep editline /usr/src/usr.bin/ssh/*
> >> >   sftp.c: fatal("Couldn't initialise editline");
> >> >   sftp.c: fatal("Couldn't initialise editline history");
> >> >
> >> > I use this line in ~/.editrc:
> >> >
> >> >   bind -v
> >> >
> >> > That gives me vi-like keybindings in many applications.  But it doesn't
> >> > work with sftp(1).
> >> 
> >> sftp does use editline, and it does read .editrc.
> >> 
> >> bind -v does do something in sftp (you'll see a behaviour change if you
> >> remove it) but it's not normal vi-like handling..
> >
> > What I see when I remove 'bind -v' from ~/.editrc is that emacs-like
> > bindings work.  So, the only effect of 'bind -v' in sftp(1) is to
> > deactivate emacs-like bindings.
> 
> editline(7) says:
> 
>  The program can switch the default to emacs mode by using the
>el_set(3) or el_parse(3) functions, and the user can switch to emacs
>mode either in the editrc(5) configuration file or interactively with
>the ed-command editor command, in all three cases executing the bind
>-e builtin command.
> 
> sftp switches the default using 'el_set(el, EL_EDITOR, "emacs")', but
> I don't see anything in editline(7) that suggests you can get back from
> there to vi mode.
> 
> you can at least automatically fix the key bindings like this:
> 
> $ cat .editrc
> bind -v
> sftp:bind -e

I prefer half supported vi bindings to emacs ones.  The information is
still useful, thank you.

> 
> 
> 

-- 
Walter



Re: Does sftp(1) support editline(3)?

2025-12-18 Thread Stuart Henderson
On 2025-12-18, Walter Alejandro Iglesias  wrote:
> On Thu, Dec 18, 2025 at 02:16:26PM -, Stuart Henderson wrote:
>> On 2025-12-18, Walter Alejandro Iglesias  wrote:
>> > I found the following in sftp(1) source code:
>> >
>> >   $ grep editline /usr/src/usr.bin/ssh/*
>> >   sftp.c: fatal("Couldn't initialise editline");
>> >   sftp.c: fatal("Couldn't initialise editline history");
>> >
>> > I use this line in ~/.editrc:
>> >
>> >   bind -v
>> >
>> > That gives me vi-like keybindings in many applications.  But it doesn't
>> > work with sftp(1).
>> 
>> sftp does use editline, and it does read .editrc.
>> 
>> bind -v does do something in sftp (you'll see a behaviour change if you
>> remove it) but it's not normal vi-like handling..
>
> What I see when I remove 'bind -v' from ~/.editrc is that emacs-like
> bindings work.  So, the only effect of 'bind -v' in sftp(1) is to
> deactivate emacs-like bindings.

editline(7) says:

 The program can switch the default to emacs mode by using the
   el_set(3) or el_parse(3) functions, and the user can switch to emacs
   mode either in the editrc(5) configuration file or interactively with
   the ed-command editor command, in all three cases executing the bind
   -e builtin command.

sftp switches the default using 'el_set(el, EL_EDITOR, "emacs")', but
I don't see anything in editline(7) that suggests you can get back from
there to vi mode.

you can at least automatically fix the key bindings like this:

$ cat .editrc
bind -v
sftp:bind -e




Re: Does sftp(1) support editline(3)?

2025-12-18 Thread Walter Alejandro Iglesias
On Thu, Dec 18, 2025 at 02:16:26PM -, Stuart Henderson wrote:
> On 2025-12-18, Walter Alejandro Iglesias  wrote:
> > I found the following in sftp(1) source code:
> >
> >   $ grep editline /usr/src/usr.bin/ssh/*
> >   sftp.c: fatal("Couldn't initialise editline");
> >   sftp.c: fatal("Couldn't initialise editline history");
> >
> > I use this line in ~/.editrc:
> >
> >   bind -v
> >
> > That gives me vi-like keybindings in many applications.  But it doesn't
> > work with sftp(1).
> 
> sftp does use editline, and it does read .editrc.
> 
> bind -v does do something in sftp (you'll see a behaviour change if you
> remove it) but it's not normal vi-like handling..

What I see when I remove 'bind -v' from ~/.editrc is that emacs-like
bindings work.  So, the only effect of 'bind -v' in sftp(1) is to
deactivate emacs-like bindings.


-- 
Walter



Re: Does sftp(1) support editline(3)?

2025-12-18 Thread Stuart Henderson
On 2025-12-18, Walter Alejandro Iglesias  wrote:
> I found the following in sftp(1) source code:
>
>   $ grep editline /usr/src/usr.bin/ssh/*
>   sftp.c: fatal("Couldn't initialise editline");
>   sftp.c: fatal("Couldn't initialise editline history");
>
> I use this line in ~/.editrc:
>
>   bind -v
>
> That gives me vi-like keybindings in many applications.  But it doesn't
> work with sftp(1).

sftp does use editline, and it does read .editrc.

bind -v does do something in sftp (you'll see a behaviour change if you
remove it) but it's not normal vi-like handling..

-- 
Please keep replies on the mailing list.