Skip to content

Commit

Permalink
Create aliases for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Krush206 committed Jun 3, 2024
1 parent b950b85 commit d840e89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sh.func.c
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,8 @@ dofunction(Char **v, struct command *c)
stderror(ERR_FUNC, Sgoal);
{
Char funcexit[] = { 'r', 'e', 't', 'u', 'r', 'n', '\0' },
*(*varvec)[2];
alarg[] = { '!', '*', '\0' },
*(*varvec)[4];
struct Strbuf aword = Strbuf_INIT,
func = Strbuf_INIT;
struct wordent *histent = NULL,
Expand Down Expand Up @@ -2847,9 +2848,16 @@ dofunction(Char **v, struct command *c)
if (!func.len)
return;
func.s[--func.len] = 0;
**(varvec = xmalloc(sizeof *varvec)) = func.s;
*varvec[1] = NULL;
**(varvec = xcalloc(1, sizeof *varvec -
(sizeof **varvec * 2))) = func.s;
setq(Sgoal, *varvec, &functions, VAR_READONLY);
**(varvec =
xcalloc(1, sizeof *varvec)) = Strsave(str2short(bname));
(*varvec)[1] = Strsave(Sgoal);
(*varvec)[2] = Strsave(alarg);
setq(Sgoal, *varvec, &aliases, VAR_READWRITE);

tw_cmd_free();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions tcsh.man.in
Original file line number Diff line number Diff line change
Expand Up @@ -5530,6 +5530,9 @@ loop at the terminal you can rub it out.
.It Ic function Ar name Xo
.Op Ar arg No ...
(+)
.It Ar name Xo
.Op Ar arg No ...
(+)
.Xc
The first form of the command prints the value of all shell functions.
.Pp
Expand All @@ -5552,6 +5555,10 @@ optionally, preceded by
which is a list of arguments to be passed.
Function calls may be nested or recursive,
but too deep a nest or recursion will raise an error.
.Pp
The fourth form is an
.Ic alias
for the third form.
.
.El
.Bl -tag -width 6n
Expand Down

0 comments on commit d840e89

Please sign in to comment.