aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/builtins.c50
-rw-r--r--src/lua_api.c6
2 files changed, 51 insertions, 5 deletions
diff --git a/src/builtins.c b/src/builtins.c
index 835e7b9..48bfa1c 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -93,11 +93,57 @@ int lush_help(lua_State *L, char ***args) {
printf("Lunar Shell, version %s\n", LUSH_VERSION);
#endif
printf("These shell commands are defined internally. Type 'help' at any "
- "time to reference this list.\n");
- printf("Available commands: \n");
+ "time to reference this list.\n\n");
+ printf("Available commands:\n");
for (int i = 0; i < lush_num_builtins(); i++) {
printf("- %s %s\n", builtin_strs[i], builtin_usage[i]);
}
+
+ char *api_strs[] = {"exec(string command)",
+ "getcwd()",
+ "debug(boolean isOn)",
+ "cd(string path)",
+ "exists(string path)",
+ "isFile(string path)",
+ "isDir(string path)",
+ "isReadable(string path)",
+ "isWriteable(string path)",
+ "lastHistory()",
+ "getHistory(int index)",
+ "getenv(string envar)",
+ "setenv(string envar, string val)",
+ "unsetenv(string envar)",
+ "setPrompt(string prompt)",
+ "alias(string alias, string command)",
+ "termCols()",
+ "termRows()",
+ "glob(string extension)",
+ "exit()"};
+ char *api_usage[] = {
+ "executes the command line chain given",
+ "gets current working directory",
+ "sets debug mode",
+ "changed current working directory to path given",
+ "checks if a file/directory exists at path",
+ "checks if given path is a file",
+ "checks if given path is a directory",
+ "checks if given path is readable",
+ "checks if given path is writeable",
+ "returns last history element",
+ "returns history at an index, 1 is most recent",
+ "returns value of an environment variable",
+ "sets the value of an environment variable",
+ "unsets the value of an environment variable",
+ "sets the prompt for the shell",
+ "sets an alias for a command",
+ "returns present number of columns in terminal",
+ "returns present number of rows in terminal",
+ "returns an array of filenames that have a given extension",
+ "ends the current process erroneously"};
+ printf("\nLunar Shell Lua API:\n\n");
+ for (int i = 0; i < sizeof(api_strs) / sizeof(char *); i++) {
+ printf("\033[1;32mlush.%s: \033[0m%s\n", api_strs[i], api_usage[i]);
+ }
return 0;
}
diff --git a/src/lua_api.c b/src/lua_api.c
index f726e44..e9473a0 100644
--- a/src/lua_api.c
+++ b/src/lua_api.c
@@ -110,7 +110,7 @@ static int execute_command(lua_State *L, const char *line) {
if (status == -1) {
fprintf(stderr, "lush: Expected end of quoted string\n");
} else if (lush_run(L, args, status) != 0) {
- exit(1);
+ return -1;
}
for (int i = 0; args[i]; i++) {
@@ -118,7 +118,7 @@ static int execute_command(lua_State *L, const char *line) {
}
free(args);
free(commands);
- return status;
+ return 0;
}
static char *get_expanded_path(const char *check_item) {
@@ -155,7 +155,7 @@ static char *get_expanded_path(const char *check_item) {
static int l_execute_command(lua_State *L) {
const char *command = luaL_checkstring(L, 1);
int status = execute_command(L, command);
- bool rc = status != -1 ? true : false;
+ bool rc = status == 0 ? true : false;
if (debug_mode) {
if (rc)