Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions nshlib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ config NSH_DISABLEBG
where a minimal footprint is a necessity and background command
execution is not.

config NSH_ALIAS
bool "Enable alias support"
default !DEFAULT_SMALL
---help---
Enable alias support for nsh. This enables command substitution from
a table of alias strings for individual commands. The maximum amount
of alias strings is configurable with NSH_ALIAS_MAX_AMOUNT.

if NSH_ALIAS

config NSH_ALIAS_MAX_AMOUNT
int "Maximum amount of aliases"
default 1
---help---
Set the maximum amount of alias entries.

endif # NSH_ALIAS

endmenu # Command Line Configuration

config NSH_BUILTIN_APPS
Expand Down
4 changes: 4 additions & 0 deletions nshlib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ ifeq ($(CONFIG_NSH_LOGIN_PASSWD),y)
CSRCS += nsh_passwdcmds.c
endif

ifeq ($(CONFIG_NSH_ALIAS),y)
CSRCS += nsh_alias.c
endif

include $(APPDIR)/Application.mk
31 changes: 31 additions & 0 deletions nshlib/nsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,25 @@ struct nsh_parser_s
#endif
};

#ifdef CONFIG_NSH_ALIAS
struct nsh_alias_s
{
FAR struct nsh_alias_s *next; /* Single link list for traversing */
FAR char *name; /* Name of the alias */
FAR char *value; /* Value behind the name */
union
{
struct
{
uint8_t exp : 1; /* Already expanded ? */
uint8_t rem : 1; /* Marked for deletion */
};

uint8_t flags; /* Raw value */
};
};
#endif

/* This is the general form of a command handler */

struct nsh_vtbl_s; /* Defined in nsh_console.h */
Expand Down Expand Up @@ -793,6 +812,13 @@ int nsh_usbconsole(void);
# define nsh_usbconsole() (-ENOSYS)
#endif

#ifdef CONFIG_NSH_ALIAS
FAR struct nsh_alias_s *nsh_aliasfind(FAR struct nsh_vtbl_s *vtbl,
FAR const char *token);
void nsh_aliasfree(FAR struct nsh_vtbl_s *vtbl,
FAR struct nsh_alias_s *alias);
#endif

#ifndef CONFIG_NSH_DISABLESCRIPT
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
FAR const char *path, bool log);
Expand Down Expand Up @@ -1193,6 +1219,11 @@ int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
# endif
#endif

#ifdef CONFIG_NSH_ALIAS
int cmd_alias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
int cmd_unalias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif

/****************************************************************************
* Name: nsh_extmatch_count
*
Expand Down
Loading