diff options
| author | 2025-02-13 11:56:52 -0500 | |
|---|---|---|
| committer | 2025-02-13 11:56:52 -0500 | |
| commit | 17aadc35445c08572edcc9df826ade5d74cb4e17 (patch) | |
| tree | 60fe317e97bc4c5304d24355fae32e2576349545 | |
| parent | v0.3.1 (diff) | |
added ability to configure alternate shell
| -rw-r--r-- | .lush/init.lua | 3 | ||||
| -rw-r--r-- | README.md | 17 | ||||
| -rwxr-xr-x[-rw-r--r--] | install.sh | 0 | ||||
| -rw-r--r-- | src/lua_api.c | 16 | ||||
| -rw-r--r-- | src/lush.c | 28 | ||||
| -rw-r--r-- | src/lush.h | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | update.sh | 0 |
7 files changed, 61 insertions, 5 deletions
diff --git a/.lush/init.lua b/.lush/init.lua index a6b5911..337c2da 100644 --- a/.lush/init.lua +++ b/.lush/init.lua @@ -34,5 +34,8 @@ lush.setPrompt("[%u@%h: %w]") -- and the command to execute with the alias lush.alias("h", "help") +-- you can set a backup shell for functionality not supported by Lunar Shell +-- lush.altShell("bash") + -- all functions from the Lunar Shell Lua API are available to you to -- customize your startup however you want @@ -14,10 +14,23 @@ Lunar Shell (lush) is an open source Linux shell with a single goal in mind. That goal is to offer the ability to write shell scripts for your operating system entirely in Lua. The Lua scripting language has many powerful features that allow for more control in the hands of the user to automate tasks on their machine. > [!NOTE] -> Lunar Shell is very early in development and may be lacking in many features common of other Linux shells. +> Lunar Shell is very early in development and may be lacking in features common of other Linux shells. ## Compiling/Installation +### Arch Linux + +``` +yay -Sy lush-shell +echo "/usr/bin/lush" | sudo tee -a /etc/shells >/dev/null +``` + +### Debain/Ubuntu/Mint + +There is a deb package in [releases](https://github.com/BanceDev/lush/releases) + +### Compile and Install from Source + Clone the repo and run the install script to get the development version. If you want the most recent stable version download the source code zip from the most recent [release](https://github.com/BanceDev/lush/releases). Extract it and run the install script. This will also automatically set your system shell to Lunar Shell, you will need to log out and back in for the changes to take effect. ``` @@ -26,7 +39,7 @@ cd lush sh install.sh ``` -To update Lunar Shell pull the repo/download the newest release and then run the install script again. +To update Lunar Shell pull the repo/download the newest release and then run the update.sh script. ## Lua Shell Scripting diff --git a/install.sh b/install.sh index ebdbaeb..ebdbaeb 100644..100755 --- a/install.sh +++ b/install.sh diff --git a/src/lua_api.c b/src/lua_api.c index ae5decf..a35a308 100644 --- a/src/lua_api.c +++ b/src/lua_api.c @@ -33,6 +33,7 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // globals static bool debug_mode = false; bool suggestion_enable = true; +char *alt_shell; // -- script execution -- int lua_load_script(lua_State *L, const char *script, char **args) { @@ -422,6 +423,19 @@ static int l_exit(lua_State *L) { return 0; } +static int l_alt_shell(lua_State *L) { + const char *alt = luaL_checkstring(L, 1); + + free(alt_shell); + alt_shell = strdup(alt); + + if (!alt_shell) { + return luaL_error(L, "Memory allocation failed"); + } + + return 1; +} + // -- register Lua functions -- void lua_register_api(lua_State *L) { @@ -470,6 +484,8 @@ void lua_register_api(lua_State *L) { lua_setfield(L, -2, "glob"); lua_pushcfunction(L, l_exit); lua_setfield(L, -2, "exit"); + lua_pushcfunction(L, l_alt_shell); + lua_setfield(L, -2, "altShell"); // set the table as global lua_setglobal(L, "lush"); } @@ -1390,6 +1390,21 @@ int lush_execute_pipeline(char ***commands, int num_commands) { return 0; } +static void build_alt_command(char *buffer, char **args) { + size_t offset = 0; + + for (int i = 0; args[i]; i++) { + if (offset + strlen(args[i]) + 1 < BUFFER_SIZE) { + strcat(buffer, args[i]); + strcat(buffer, " "); + offset = strlen(buffer); + } else { + fprintf(stderr, "command too long\n"); + exit(EXIT_FAILURE); + } + } +} + int lush_execute_command(char **args, int input_fd, int output_fd) { // create child pid_t pid; @@ -1419,8 +1434,15 @@ int lush_execute_command(char **args, int input_fd, int output_fd) { // execute the command if (execvp(args[0], args) == -1) { - perror("execvp"); - exit(EXIT_FAILURE); + if (alt_shell) { + char command[BUFFER_SIZE] = {0}; + build_alt_command(command, args); + execlp(alt_shell, alt_shell, "-c", command, (char *)NULL); + perror("alt shell"); + } else { + perror("lush"); + exit(EXIT_FAILURE); + } } } else if (pid < 0) { // forking failed @@ -1592,5 +1614,7 @@ int main(int argc, char *argv[]) { free(prompt_format); if (aliases != NULL) free(aliases); + if (alt_shell != NULL) + free(alt_shell); return 0; } @@ -55,9 +55,9 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands); void lush_format_prompt(const char *prompt_format); -// enable for autocomplete text set in init.lua // initialized in the lua_api extern bool suggestion_enable; +extern char *alt_shell; // format spec for the prompt extern char *prompt_format; |
