From 6ef7c83e19eae145e40f5d8cc9da82484546052a Mon Sep 17 00:00:00 2001 From: Lance Borden Date: Tue, 19 Aug 2025 15:09:00 -0400 Subject: update install script paths --- .lush/init.lua | 41 ----------------- .lush/scripts/example.lua | 112 ---------------------------------------------- install.sh | 6 +-- lush/init.lua | 41 +++++++++++++++++ lush/scripts/example.lua | 112 ++++++++++++++++++++++++++++++++++++++++++++++ src/lua_api.c | 4 +- 6 files changed, 158 insertions(+), 158 deletions(-) delete mode 100644 .lush/init.lua delete mode 100644 .lush/scripts/example.lua create mode 100644 lush/init.lua create mode 100644 lush/scripts/example.lua diff --git a/.lush/init.lua b/.lush/init.lua deleted file mode 100644 index 337c2da..0000000 --- a/.lush/init.lua +++ /dev/null @@ -1,41 +0,0 @@ ---[[ -Copyright (c) 2024, Lance Borden -All rights reserved. - -This software is licensed under the BSD 3-Clause License. -You may obtain a copy of the license at: -https://opensource.org/licenses/BSD-3-Clause - -Redistribution and use in source and binary forms, with or without -modification, are permitted under the conditions stated in the BSD 3-Clause -License. - -THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -]] - --- This file is your init.lua. It will be automatically executed each time you open --- a new session of Lunar Shell. - --- Setting environment variables -local path = lush.getenv("HOME") .. "/bin:" .. lush.getenv("PATH") -lush.setenv("PATH", path) - --- you can choose to enable/disable inline suggestions -lush.suggestions(true) - --- the prompt can be customized here too --- %u is username, %h is hostname, %w is current working directory --- %t is current time in hr:min:sec, %d is date in MM/DD/YYYY -lush.setPrompt("[%u@%h: %w]") - --- aliases can be defined using the alias method by passing the alias name --- 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 diff --git a/.lush/scripts/example.lua b/.lush/scripts/example.lua deleted file mode 100644 index e7cd210..0000000 --- a/.lush/scripts/example.lua +++ /dev/null @@ -1,112 +0,0 @@ ---[[ -Copyright (c) 2024, Lance Borden -All rights reserved. - -This software is licensed under the BSD 3-Clause License. -You may obtain a copy of the license at: -https://opensource.org/licenses/BSD-3-Clause - -Redistribution and use in source and binary forms, with or without -modification, are permitted under the conditions stated in the BSD 3-Clause -License. - -THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -]] - --- This file is a demo of all of the commands Lunar Shell has in its Lua API --- the Lua file itself is the executable unit so all code is run line by line - --- All Lua specific tools still work here too. Functions, loops, conditionals, --- tables, Lua's standard library, etc are all available to integrate with Lunar Shell - -print("Welcome to Lunar Shell scripting") - --- command line args can be passed to lua programs --- done like so: example.lua arg1 arg2 ... --- args can be read using the global args tables -if args ~= nil then - print("Printing args:") - for i = 1, #args do - print(args[i]) - end -end - --- exec can be used to run any command line prompt --- this method is much more native than using os.execute and is the recommended function --- it also returns a boolean on if the command executed successfully -if lush.exec('echo "hello world"\n') then - print("echo worked properly") -end - --- debug mode can be used to log execution of commands -lush.debug(true) -- enters debug -lush.exec('echo "echo in debug mode"') -lush.debug(false) -- exits debug - --- getcwd returns the current working directory -local cwd = lush.getcwd() -print(cwd) - --- exec also supports piping --- this comment will get grepped since it says hello -lush.cd("~/.lush/scripts") -lush.exec('cat "example.lua" | grep "hello" | sort | uniq') -lush.cd(cwd) - --- exists allows you to check if a file or directory exists -if lush.exists("~/.lush/scripts/example.lua") then - print("example.lua exists") -end - --- isFile and isDir check if a path points to a file or a directory -if lush.isFile("~/.lush/scripts/example.lua") then - print("example.lua is a file") -end - -if not lush.isDirectory("~/.lush/scripts/example.lua") then - print("example.lua is not a directory") -end - --- you can also check if a file is readable/writeable -if lush.isReadable("~/.lush/scripts/example.lua") then - print("example.lua is readable") -end -if lush.isWriteable("~/.lush/scripts/example.lua") then - print("example.lua is writeable") -end - --- you can fetch the most recently executed command in history -print("Most recent history: " .. lush.lastHistory()) - --- you can also fetch history at a certain index in the past (1 being most recent) -print("Most recent history indexed: " .. lush.getHistory(1)) - --- you can set environment variables using putenv -lush.setenv("EXAMPLE", "Lunar Shell Example") - --- you can get an environment variable using getenv -print("Value of EXAMPLE: " .. lush.getenv("EXAMPLE")) - --- you can unset an environment variable with unsetenv -lush.unsetenv("EXAMPLE") - --- you can get the current terminal width(cols) and height(rows) --- this function is very useful if you want to make certain kinds of custom prompts in your init.lua -print("Terminal Columns: " .. lush.termCols()) -print("Terminal Rows: " .. lush.termRows()) - --- the glob function scans the current working directory for files with the given extension and returns --- them as an array of strings -local textFiles = lush.glob("txt") -if textFiles ~= nil then - print("Printing txt files:") - for i = 1, #textFiles do - print(textFiles[i]) - end -end - --- the exit function is used to make the program quit in the case of an error -print("making an error with lush.exit()") -lush.exit() diff --git a/install.sh b/install.sh index 405cf6e..2251fed 100755 --- a/install.sh +++ b/install.sh @@ -54,12 +54,12 @@ rm premake.tar.gz premake5 gmake make -if [ ! -d ~/.lush ]; then - cp -rf ./.lush ~/ +if [ ! -d ~/.config/lush ]; then + cp -rf ./lush ~/.config/ fi # always update example -cp -f ./.lush/scripts/example.lua ~/.lush/scripts/example.lua +cp -f ./lush/scripts/example.lua ~/config/lush/scripts/example.lua # Install the new shell binary to a temporary location sudo cp ./bin/Debug/lush/lush /usr/bin/lush.new diff --git a/lush/init.lua b/lush/init.lua new file mode 100644 index 0000000..337c2da --- /dev/null +++ b/lush/init.lua @@ -0,0 +1,41 @@ +--[[ +Copyright (c) 2024, Lance Borden +All rights reserved. + +This software is licensed under the BSD 3-Clause License. +You may obtain a copy of the license at: +https://opensource.org/licenses/BSD-3-Clause + +Redistribution and use in source and binary forms, with or without +modification, are permitted under the conditions stated in the BSD 3-Clause +License. + +THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +]] + +-- This file is your init.lua. It will be automatically executed each time you open +-- a new session of Lunar Shell. + +-- Setting environment variables +local path = lush.getenv("HOME") .. "/bin:" .. lush.getenv("PATH") +lush.setenv("PATH", path) + +-- you can choose to enable/disable inline suggestions +lush.suggestions(true) + +-- the prompt can be customized here too +-- %u is username, %h is hostname, %w is current working directory +-- %t is current time in hr:min:sec, %d is date in MM/DD/YYYY +lush.setPrompt("[%u@%h: %w]") + +-- aliases can be defined using the alias method by passing the alias name +-- 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 diff --git a/lush/scripts/example.lua b/lush/scripts/example.lua new file mode 100644 index 0000000..e7cd210 --- /dev/null +++ b/lush/scripts/example.lua @@ -0,0 +1,112 @@ +--[[ +Copyright (c) 2024, Lance Borden +All rights reserved. + +This software is licensed under the BSD 3-Clause License. +You may obtain a copy of the license at: +https://opensource.org/licenses/BSD-3-Clause + +Redistribution and use in source and binary forms, with or without +modification, are permitted under the conditions stated in the BSD 3-Clause +License. + +THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +]] + +-- This file is a demo of all of the commands Lunar Shell has in its Lua API +-- the Lua file itself is the executable unit so all code is run line by line + +-- All Lua specific tools still work here too. Functions, loops, conditionals, +-- tables, Lua's standard library, etc are all available to integrate with Lunar Shell + +print("Welcome to Lunar Shell scripting") + +-- command line args can be passed to lua programs +-- done like so: example.lua arg1 arg2 ... +-- args can be read using the global args tables +if args ~= nil then + print("Printing args:") + for i = 1, #args do + print(args[i]) + end +end + +-- exec can be used to run any command line prompt +-- this method is much more native than using os.execute and is the recommended function +-- it also returns a boolean on if the command executed successfully +if lush.exec('echo "hello world"\n') then + print("echo worked properly") +end + +-- debug mode can be used to log execution of commands +lush.debug(true) -- enters debug +lush.exec('echo "echo in debug mode"') +lush.debug(false) -- exits debug + +-- getcwd returns the current working directory +local cwd = lush.getcwd() +print(cwd) + +-- exec also supports piping +-- this comment will get grepped since it says hello +lush.cd("~/.lush/scripts") +lush.exec('cat "example.lua" | grep "hello" | sort | uniq') +lush.cd(cwd) + +-- exists allows you to check if a file or directory exists +if lush.exists("~/.lush/scripts/example.lua") then + print("example.lua exists") +end + +-- isFile and isDir check if a path points to a file or a directory +if lush.isFile("~/.lush/scripts/example.lua") then + print("example.lua is a file") +end + +if not lush.isDirectory("~/.lush/scripts/example.lua") then + print("example.lua is not a directory") +end + +-- you can also check if a file is readable/writeable +if lush.isReadable("~/.lush/scripts/example.lua") then + print("example.lua is readable") +end +if lush.isWriteable("~/.lush/scripts/example.lua") then + print("example.lua is writeable") +end + +-- you can fetch the most recently executed command in history +print("Most recent history: " .. lush.lastHistory()) + +-- you can also fetch history at a certain index in the past (1 being most recent) +print("Most recent history indexed: " .. lush.getHistory(1)) + +-- you can set environment variables using putenv +lush.setenv("EXAMPLE", "Lunar Shell Example") + +-- you can get an environment variable using getenv +print("Value of EXAMPLE: " .. lush.getenv("EXAMPLE")) + +-- you can unset an environment variable with unsetenv +lush.unsetenv("EXAMPLE") + +-- you can get the current terminal width(cols) and height(rows) +-- this function is very useful if you want to make certain kinds of custom prompts in your init.lua +print("Terminal Columns: " .. lush.termCols()) +print("Terminal Rows: " .. lush.termRows()) + +-- the glob function scans the current working directory for files with the given extension and returns +-- them as an array of strings +local textFiles = lush.glob("txt") +if textFiles ~= nil then + print("Printing txt files:") + for i = 1, #textFiles do + print(textFiles[i]) + end +end + +-- the exit function is used to make the program quit in the case of an error +print("making an error with lush.exit()") +lush.exit() diff --git a/src/lua_api.c b/src/lua_api.c index 0e20752..25f2f94 100644 --- a/src/lua_api.c +++ b/src/lua_api.c @@ -44,8 +44,8 @@ int lua_load_script(lua_State *L, const char *script, char **args) { } else { const char *home_dir = getenv("HOME"); if (home_dir != NULL) { - snprintf(script_path, sizeof(script_path), "%s/.lush/scripts/%s", - home_dir, script); + snprintf(script_path, sizeof(script_path), + "%s/.config/lush/scripts/%s", home_dir, script); if (access(script_path, F_OK) != 0) { // script not in either location -- cgit v1.2.3-59-g8ed1b