1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-12 19:22:41 +00:00

Default to emacs upon invoking interactive shell

If the VISUAL or EDITOR environment variable is not set to a value
matching *[Vv][Ii]* or *macs* at initialisation time, then ksh does
not turn on any line editor.

This is user-hostile. New users on Unix-like systems typically have
a simple editor like nano preconfigured as their default, or may
not have the VISUAL or EDITOR variable set at all. So if they try
ksh, they find themselves without basic functionality such as arrow
keys and probably go straight back to bash.

The emacs line editor is by far the most widely used, especially
among new users, so ksh should default to that. Most other shells
already do this.

src/cmd/ksh93/sh/main.c: sh_main():
- On an interactive shell, if on editor was turned on based on
  $VISUAL or $EDITOR, turn on emacs before reading input.
This commit is contained in:
Martijn Dekker 2022-02-01 23:38:14 +00:00
parent d650c73e55
commit 1375cda934
5 changed files with 62 additions and 34 deletions

6
NEWS
View file

@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
Any uppercase BUG_* names are modernish shell bug IDs.
2022-02-01:
- Upon invocation, the interactive shell no longer leaves the user without
a line editor if the VISUAL or EDITOR variable does not indicate emacs,
gmacs or vi; instead, it now turns on the emacs option by default.
2022-01-31:
- Improved keyboard support for the vi and emacs built-in line editors:

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2022-01-31" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2022-02-01" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -1848,15 +1848,11 @@ If the
.B
.SM VISUAL
variable is not set,
the value of this variable will be checked for the patterns
as described with
the value of this variable will be checked for certain patterns
and the corresponding editing option will be turned on as described with
.B
.SM VISUAL
below and the corresponding editing option
(see Special Command
.B set
below)
will be turned on.
below.
.TP
.SM
.B ENV
@ -2274,26 +2270,34 @@ for this value which cannot be exceeded.)
.TP
.B
.SM VISUAL
If the value of this variable matches the pattern
.IR *[Vv][Ii]* ,
then the
.B vi
option
(see Special Command
.B set
The value of this variable is scanned when the shell is invoked
and whenever its value is changed;
if it is found to match certain patterns,
the corresponding line editor
(see
.I In-line Editing Options
below)
is turned on.
If the value matches the pattern
.I *gmacs* ,
is activated.
If it matches the pattern
.IR *[Vv][Ii]* ,
the
.B vi
option is turned on;
else if it matches the pattern
.IR *gmacs* ,
the
.B gmacs
option is turned on.
If the value matches the pattern
option is turned on;
else if it matches the pattern
.IR *macs* ,
then the
the
.B emacs
option
will be turned on.
option is turned on.
If none of the patterns match,
.B emacs
is turned on by default upon initializing an interactive shell.
If the value is changed by assignment and none of the patterns match,
no options are changed.
The value of
.B
.SM VISUAL
@ -4710,7 +4714,7 @@ If either the
or
.B vi
option is active, the user can edit the command line.
To be in either of these edit modes
To be in either of these edit modes,
.B set
the corresponding
option.
@ -4720,8 +4724,11 @@ An editing option is automatically selected each time the
or
.SM
.B EDITOR
variable is assigned a value ending in either of these
option names.
variable is assigned a value matching any of these editor names;
for details, see
.I Shell Variables
above under
.BR VISUAL .
.PP
The editing features require that the user's terminal
accept `RETURN' as carriage return without line feed
@ -4742,8 +4749,8 @@ at least 8 columns to enter input, the prompt is truncated from the
left.
If the line is longer than the window width minus two, a mark is
displayed at the end of the window to notify the user.
As the cursor moves and reaches the window boundaries the window will be
centered about the cursor.
As the cursor moves and reaches the window boundaries,
the window will be centered about the cursor.
The mark is a
.BR > " (<" ,
.BR * )

View file

@ -346,7 +346,18 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
fixargs(sh.st.dolv,1);
}
if(sh_isoption(SH_INTERACTIVE))
{
sh_onstate(SH_INTERACTIVE);
#if SHOPT_ESH
/* do not leave users without a line editor */
if(!sh_isoption(SH_GMACS)
#if SHOPT_VSH
&& !sh_isoption(SH_VI)
#endif /* SHOPT_VSH */
)
sh_onoption(SH_EMACS);
#endif /* SHOPT_ESH */
}
nv_putval(IFSNOD,(char*)e_sptbnl,NV_RDONLY);
exfile(iop,fdin);
sh_done(0);

View file

@ -471,9 +471,11 @@ L raw Bourne mode literal tab characters
# characters to spaces on the command line. See slowread() in io.c.
p :test-1:
w true /de\tv/nu\tl\tl
r ^:test-1: true (/de\tv/nu\tl\tl|/de v/nu l l)\r\n$
w set +o emacs 2>/dev/null
p :test-2:
w true /de\tv/nu\tl\tl
r ^:test-2: true (/de\tv/nu\tl\tl|/de v/nu l l)\r\n$
p :test-3:
!
VISUAL='' tst $LINENO <<"!"
@ -483,13 +485,15 @@ L raw Bourne mode backslash handling
# This is tested with both erase and kill characters.
p :test-1:
w stty erase ^H kill ^X
w set +o emacs 2>/dev/null
p :test-2:
w true string\\\\\cH\cH
r ^:test-2: true string\r\n$
w stty erase ^H kill ^X
p :test-3:
w true string\\\\\cH\cH
r ^:test-3: true string\r\n$
p :test-4:
w true incorrect\\\cXtrue correct
r ^:test-3: true correct\r\n$
r ^:test-4: true correct\r\n$
!
set --