mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
Load 'r' and 'history' default aliases on interactive only
These two default aliases are useful on interactive shells. In scripts, they interfere with possible function or command names. As of this commit, these final two default aliases are only loaded for interactive shells, leaving zero default aliases for scripts. This completes the project to get rid of misguided default aliases. src/cmd/ksh93/include/shtable.h, src/cmd/ksh93/data/aliases.c: src/cmd/ksh93/sh/init.c: - Add empty alias table shtab_noaliases[] for scripts. - Rename inittree() to sh_inittree() and make it external. - nv_init(), sh_reinit(): Initialise empty alias tree for scripts. src/cmd/ksh93/sh/main.c: sh_main(): - If interactive, reinitialise alias tree for interactive shells. src/cmd/ksh93/tests/alias.sh: - To test default alias removal, launch shell with -i.
This commit is contained in:
parent
a42ac7e77a
commit
17f81ebedb
7 changed files with 23 additions and 29 deletions
3
NEWS
3
NEWS
|
@ -10,6 +10,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
that 'unalias -a' does not remove them. Shell functions can now use
|
that 'unalias -a' does not remove them. Shell functions can now use
|
||||||
these names, which improves compatibility with POSIX shell scripts.
|
these names, which improves compatibility with POSIX shell scripts.
|
||||||
|
|
||||||
|
- The two default aliases that are left, 'history' and 'r', are now only
|
||||||
|
loaded on interactive shells, leaving zero default aliases for scripts.
|
||||||
|
|
||||||
- The End key escape sequence '^[[F' is now handled in the emacs and vi editing
|
- The End key escape sequence '^[[F' is now handled in the emacs and vi editing
|
||||||
modes. The End key moves the cursor to the end of the line (in contrast to
|
modes. The End key moves the cursor to the end of the line (in contrast to
|
||||||
the Home key doing the opposite).
|
the Home key doing the opposite).
|
||||||
|
|
21
TODO
21
TODO
|
@ -14,27 +14,6 @@ Fix build system:
|
||||||
to take effect. The machine-generated Mamfiles are now used as a fallback,
|
to take effect. The machine-generated Mamfiles are now used as a fallback,
|
||||||
but they are not meant to be edited by hand.
|
but they are not meant to be edited by hand.
|
||||||
|
|
||||||
______
|
|
||||||
Fix or remove broken or misguided default aliases:
|
|
||||||
|
|
||||||
- Make proper builtins out of the following scripting-related aliases, so
|
|
||||||
that 'unalias -a' does not eliminate them. If done correctly, this causes
|
|
||||||
no other change in behaviour. It would be good practice to 'unalias -a' in
|
|
||||||
a script to start with a clean slate, except ksh has always made that
|
|
||||||
impossible without losing these. Default aliases should be to facilitate
|
|
||||||
interactive use.
|
|
||||||
- autoload='typeset -fu'
|
|
||||||
- compound='typeset -C'
|
|
||||||
- float='typeset -lE'
|
|
||||||
- functions='typeset -f'
|
|
||||||
- integer='typeset -li'
|
|
||||||
- nameref='typeset -n'
|
|
||||||
Keep these default aliases for the benefit of interactive shells:
|
|
||||||
+ history='hist -l'
|
|
||||||
+ r='hist -s'
|
|
||||||
To avoid interfering with shell functions by those names that POSIX
|
|
||||||
scripts may set, those should only initialise on interactive shells.
|
|
||||||
|
|
||||||
______
|
______
|
||||||
Fix currently known bugs affecting shell scripting. These are identified by
|
Fix currently known bugs affecting shell scripting. These are identified by
|
||||||
their modernish IDs. For exact details, see code/comments in:
|
their modernish IDs. For exact details, see code/comments in:
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "FEATURE/dynamic"
|
#include "FEATURE/dynamic"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the table of built-in aliases. These should be exported.
|
* Table of built-in aliases for interactive shells.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const struct shtable2 shtab_aliases[] =
|
const struct shtable2 shtab_aliases[] =
|
||||||
|
@ -34,3 +34,12 @@ const struct shtable2 shtab_aliases[] =
|
||||||
"", 0, (char*)0
|
"", 0, (char*)0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Empty table of built-in aliases for non-interactive shells.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const struct shtable2 shtab_noaliases[] =
|
||||||
|
{
|
||||||
|
"", 0, (char*)0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,12 @@ extern const Shtable_t shtab_options[];
|
||||||
extern const Shtable_t shtab_attributes[];
|
extern const Shtable_t shtab_attributes[];
|
||||||
extern const struct shtable2 shtab_variables[];
|
extern const struct shtable2 shtab_variables[];
|
||||||
extern const struct shtable2 shtab_aliases[];
|
extern const struct shtable2 shtab_aliases[];
|
||||||
|
extern const struct shtable2 shtab_noaliases[];
|
||||||
extern const struct shtable2 shtab_signals[];
|
extern const struct shtable2 shtab_signals[];
|
||||||
extern const struct shtable3 shtab_builtins[];
|
extern const struct shtable3 shtab_builtins[];
|
||||||
extern const Shtable_t shtab_reserved[];
|
extern const Shtable_t shtab_reserved[];
|
||||||
extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
|
extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
|
||||||
extern int sh_lookopt(const char*, int*);
|
extern int sh_lookopt(const char*, int*);
|
||||||
|
extern Dt_t *sh_inittree(Shell_t*, const struct shtable2*);
|
||||||
|
|
||||||
#endif /* SH_TABLE_H */
|
#endif /* SH_TABLE_H */
|
||||||
|
|
|
@ -217,7 +217,6 @@ static int lctype;
|
||||||
static int nbltins;
|
static int nbltins;
|
||||||
static void env_init(Shell_t*);
|
static void env_init(Shell_t*);
|
||||||
static Init_t *nv_init(Shell_t*);
|
static Init_t *nv_init(Shell_t*);
|
||||||
static Dt_t *inittree(Shell_t*,const struct shtable2*);
|
|
||||||
static int shlvl;
|
static int shlvl;
|
||||||
|
|
||||||
#ifdef _WINIX
|
#ifdef _WINIX
|
||||||
|
@ -1561,7 +1560,7 @@ int sh_reinit(char *argv[])
|
||||||
nv_delete(np,dp,NV_NOFREE);
|
nv_delete(np,dp,NV_NOFREE);
|
||||||
}
|
}
|
||||||
dtclose(shp->alias_tree);
|
dtclose(shp->alias_tree);
|
||||||
shp->alias_tree = inittree(shp,shtab_aliases);
|
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
|
||||||
shp->last_root = shp->var_tree;
|
shp->last_root = shp->var_tree;
|
||||||
shp->inuse_bits = 0;
|
shp->inuse_bits = 0;
|
||||||
if(shp->userinit)
|
if(shp->userinit)
|
||||||
|
@ -1760,7 +1759,7 @@ static Init_t *nv_init(Shell_t *shp)
|
||||||
shp->nvfun.last = (char*)shp;
|
shp->nvfun.last = (char*)shp;
|
||||||
shp->nvfun.nofree = 1;
|
shp->nvfun.nofree = 1;
|
||||||
ip->sh = shp;
|
ip->sh = shp;
|
||||||
shp->var_base = shp->var_tree = inittree(shp,shtab_variables);
|
shp->var_base = shp->var_tree = sh_inittree(shp,shtab_variables);
|
||||||
SHLVL->nvalue.ip = &shlvl;
|
SHLVL->nvalue.ip = &shlvl;
|
||||||
ip->IFS_init.hdr.disc = &IFS_disc;
|
ip->IFS_init.hdr.disc = &IFS_disc;
|
||||||
ip->PATH_init.disc = &RESTRICTED_disc;
|
ip->PATH_init.disc = &RESTRICTED_disc;
|
||||||
|
@ -1853,9 +1852,9 @@ static Init_t *nv_init(Shell_t *shp)
|
||||||
(MCHKNOD)->nvalue.lp = (&sh_mailchk);
|
(MCHKNOD)->nvalue.lp = (&sh_mailchk);
|
||||||
(OPTINDNOD)->nvalue.lp = (&shp->st.optindex);
|
(OPTINDNOD)->nvalue.lp = (&shp->st.optindex);
|
||||||
/* set up the seconds clock */
|
/* set up the seconds clock */
|
||||||
shp->alias_tree = inittree(shp,shtab_aliases);
|
shp->alias_tree = sh_inittree(shp,shtab_noaliases);
|
||||||
shp->track_tree = dtopen(&_Nvdisc,Dtset);
|
shp->track_tree = dtopen(&_Nvdisc,Dtset);
|
||||||
shp->bltin_tree = inittree(shp,(const struct shtable2*)shtab_builtins);
|
shp->bltin_tree = sh_inittree(shp,(const struct shtable2*)shtab_builtins);
|
||||||
shp->fun_tree = dtopen(&_Nvdisc,Dtoset);
|
shp->fun_tree = dtopen(&_Nvdisc,Dtoset);
|
||||||
dtview(shp->fun_tree,shp->bltin_tree);
|
dtview(shp->fun_tree,shp->bltin_tree);
|
||||||
nv_mount(DOTSHNOD, "type", shp->typedict=dtopen(&_Nvdisc,Dtoset));
|
nv_mount(DOTSHNOD, "type", shp->typedict=dtopen(&_Nvdisc,Dtoset));
|
||||||
|
@ -1878,7 +1877,7 @@ static Init_t *nv_init(Shell_t *shp)
|
||||||
* initialize name-value pairs
|
* initialize name-value pairs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Dt_t *inittree(Shell_t *shp,const struct shtable2 *name_vals)
|
Dt_t *sh_inittree(Shell_t *shp,const struct shtable2 *name_vals)
|
||||||
{
|
{
|
||||||
register Namval_t *np;
|
register Namval_t *np;
|
||||||
register const struct shtable2 *tp;
|
register const struct shtable2 *tp;
|
||||||
|
|
|
@ -176,6 +176,8 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
||||||
{
|
{
|
||||||
sh_onoption(SH_BGNICE);
|
sh_onoption(SH_BGNICE);
|
||||||
sh_onoption(SH_RC);
|
sh_onoption(SH_RC);
|
||||||
|
free(shp->alias_tree);
|
||||||
|
shp->alias_tree = sh_inittree(shp,shtab_aliases);
|
||||||
}
|
}
|
||||||
if(!sh_isoption(SH_RC) && (sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX)
|
if(!sh_isoption(SH_RC) && (sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX)
|
||||||
#if SHOPT_REMOTE
|
#if SHOPT_REMOTE
|
||||||
|
|
|
@ -110,7 +110,7 @@ unalias foo
|
||||||
unalias foo && err_exit 'unalias should return non-zero when a previously set alias is unaliased twice'
|
unalias foo && err_exit 'unalias should return non-zero when a previously set alias is unaliased twice'
|
||||||
|
|
||||||
# Removing a predefined alias should work without an error from free(3)
|
# Removing a predefined alias should work without an error from free(3)
|
||||||
$SHELL -c 'unalias history' 2> /dev/null || err_exit 'removing a predefined alias does not work'
|
$SHELL -i -c 'unalias history' 2> /dev/null || err_exit 'removing a predefined alias does not work'
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Reference in a new issue