1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Reinstate 'r' and 'history' as preset aliases for interactive ksh

Following a community discussion, it became clear that 'r' is
particularly problematic as a regular builtin, as the name can and
does conflict with at least one legit external command by that
name. There was a consensus against removing it altogether and
letting users set the alias in their login scripts. However,
aliases are easier to bypass, remove or rename than builtins are.
My compromise is to reinstate 'r' as a preset alias on interactive
shells only, along with 'history', as was done in 17f81ebe before
they were converted to builtins in 03224ae3. So this reintroduces
the notion of predefined aliases to ksh 93u+m, but only for
interactive shells that are not initialised in POSIX mode.

src/cmd/ksh93/Makefile,
src/cmd/ksh93/Mamfile,
src/cmd/ksh93/include/shtable.h,
src/cmd/ksh93/data/aliases.c:
- Restore aliases.c containing shtab_aliases[], a table specifying
  the preset aliases.

src/cmd/ksh93/include/shtable.h,
src/cmd/ksh93/sh/init.c:
- Rename inittree() to sh_inittree() and make it extern, because we
  need to use it in main.c (sh_main()).

src/cmd/ksh93/sh/main.c: sh_main():
- Init preset aliases from shtab_aliases[] only if the shell is
  interactive and not in POSIX mode.

src/cmd/ksh93/bltins/typeset.c,
src/cmd/ksh93/tests/alias.sh:
- unall(): When unsetting an alias, pass on the NV_NOFREE attribute
  to nv_delete() to avoid an erroneous attempt to free a preset
  alias from read-only memory. See: 5d50f825

src/cmd/ksh93/data/builtins.c:
- Remove "history" and "r" entries from shtab_builtins[].
- Revert changes to inline fc/hist docs in sh_opthist[].

src/cmd/ksh93/bltins/hist.c: b_hist():
- Remove handling for 'history' and 'r' as builtins.

src/cmd/ksh93/sh.1:
- Update accordingly.

Resolves: https://github.com/ksh93/ksh/issues/125
This commit is contained in:
Martijn Dekker 2020-09-11 20:51:35 +02:00
parent 777dfa3e59
commit ddaa145b3d
12 changed files with 90 additions and 37 deletions

View file

@ -90,8 +90,6 @@ const struct shtable3 shtab_builtins[] =
"exit", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(return),
"fc", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
"hist", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
"history", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
"r", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
"readonly", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(readonly),
"shift", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(shift),
"trap", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(trap),
@ -925,15 +923,11 @@ const char sh_opthash[] =
;
const char sh_opthist[] =
"[-1cn?@(#)$Id: hist (AT&T Research/ksh93) 2020-07-16 $\n]"
"[-1cn?@(#)$Id: hist (AT&T Research) 2000-04-02 $\n]"
USAGE_LICENSE
"[+NAME?fc, hist, history, r - process command history list]"
"[+DESCRIPTION?\bhist\b lists, edits, or re-executes commands "
"[+NAME?\f?\f - process command history list]"
"[+DESCRIPTION?\b\f?\f\b lists, edits, or re-executes, commands "
"previously entered into the current shell environment.]"
"[+?The following command equivalents exist: "
"\bfc\b is \bhist\b; "
"\bhistory\b is \bhist -l\b (list history); "
"and \br\b is \bhist -s\b (reexecute command).]"
"[+?The command history list references commands by number. The first number "
"in the list is selected arbitrarily. The relationship of a number "
"to its command does not change during a login session. When the "
@ -941,11 +935,11 @@ USAGE_LICENSE
"maintains the ordering.]"
"[+?When commands are edited (when the \b-l\b option is not specified), the "
"resulting lines will be entered at the end of the history list and "
"then reexecuted by the current shell. The \bhist\b command that "
"then reexecuted by the current shell. The \b\f?\f\b command that "
"caused the editing will not be entered into the history list. If the "
"editor returns a non-zero exit status, this will suppress the "
"entry into the history list and the command reexecution. Command "
"line variable assignments and redirections affect both the \bhist\b "
"line variable assignments and redirections affect both the \f?\f "
"command and the commands that are reexecuted.]"
"[+?\afirst\a and \alast\a define the range of commands. \afirst\a and "
"\alast\a can be one of the following:]{"