From 90ed12d55132586ea83d4683459053606d116597 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 9 Jul 2022 17:04:50 -0400 Subject: [PATCH 1/5] feat: add hilbish.init hook (closes #186) --- CHANGELOG.md | 1 + main.go | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2a091..5e056df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ having and using multiple runners. - `fs.pathListSep` is the separator for $PATH env entries - Lua modules located in `hilbish.userDir.data .. '/hilbish/start'` (like `~/.local/share/hilbish/start/foo/init.lua`) will be ran on startup +- `hilbish.init` hook, thrown after Hilbish has initialized Lua side ### Changed - **Breaking Change:** Upgraded to Lua 5.4. diff --git a/main.go b/main.go index 9421bfc..ce1a7f3 100644 --- a/main.go +++ b/main.go @@ -138,6 +138,7 @@ func main() { } else { runConfig(*configflag) } + hooks.Em.Emit("hilbish.init") if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 { scanner := bufio.NewScanner(bufio.NewReader(os.Stdin)) From a106f4aea0e80d96b81317bc806d547a7f23acc7 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 9 Jul 2022 17:15:13 -0400 Subject: [PATCH 2/5] refactor!: move hilbish.greeting to an opt (closes #184) --- .hilbishrc.lua | 2 -- CHANGELOG.md | 5 +++-- api.go | 6 ------ nature/opts/greeting.lua | 8 ++++++++ nature/opts/init.lua | 5 ++++- 5 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 nature/opts/greeting.lua diff --git a/.hilbishrc.lua b/.hilbishrc.lua index 4a06b26..5d6382b 100644 --- a/.hilbishrc.lua +++ b/.hilbishrc.lua @@ -9,8 +9,6 @@ local function doPrompt(fail) )) end -print(lunacolors.format(hilbish.greeting)) - doPrompt() bait.catch('command.exit', function(code) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e056df..efda87e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,12 +77,13 @@ It can (at the moment) have 4 variables: User input has been added to the return to account for runners wanting to prompt for continued input, and to add it properly to history. `continue` got added so that it would be easier for runners to get continued input -without having to actually handle it at all. - +without having to actually handle it at all. - **Breaking Change:** Job objects and timers are now Lua userdata instead of a table, so their functions require you to call them with a colon instead of a dot. (ie. `job.stop()` -> `job:stop()`) - All `fs` module functions which take paths now implicitly expand ~ to home. +- **Breaking Change:** `hilbish.greeting` has been moved to an opt (`hilbish.opts.greeting`) and is +always printed by default. To disable it, set the opt to false. ### Fixed - If in Vim replace mode, input at the end of the line inserts instead of diff --git a/api.go b/api.go index 3aca037..dacae02 100644 --- a/api.go +++ b/api.go @@ -44,7 +44,6 @@ var exports = map[string]util.LuaExport{ "which": {hlwhich, 1, false}, } -var greeting string var hshMod *rt.Table var hilbishLoader = packagelib.Loader{ Load: hilbishLoad, @@ -103,10 +102,6 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) { username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows } - greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + username + `{reset}. -The nice lil shell for {blue}Lua{reset} fanatics! -Check out the {blue}{bold}guide{reset} command to get started. -` util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()), "Hilbish version") util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user") util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine") @@ -114,7 +109,6 @@ Check out the {blue}{bold}guide{reset} command to get started. util.SetFieldProtected(fakeMod, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files") util.SetFieldProtected(fakeMod, mod, "interactive", rt.BoolValue(interactive), "If this is an interactive shell") util.SetFieldProtected(fakeMod, mod, "login", rt.BoolValue(login), "Whether this is a login shell") - util.SetFieldProtected(fakeMod, mod, "greeting", rt.StringValue(greeting), "Hilbish's welcome message for interactive shells. It has Lunacolors formatting.") util.SetFieldProtected(fakeMod, mod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)") util.SetFieldProtected(fakeMod, mod, "exitCode", rt.IntValue(0), "Exit code of last exected command") util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.") diff --git a/nature/opts/greeting.lua b/nature/opts/greeting.lua new file mode 100644 index 0000000..ed408d7 --- /dev/null +++ b/nature/opts/greeting.lua @@ -0,0 +1,8 @@ +local bait = require 'bait' +local lunacolors = require 'lunacolors' + +bait.catch('hilbish.init', function() + if hilbish.interactive and type(hilbish.opts.greeting) == 'string' then + print(lunacolors.format(hilbish.opts.greeting)) + end +end) diff --git a/nature/opts/init.lua b/nature/opts/init.lua index 59d3cbd..d9de420 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -20,7 +20,10 @@ local function setupOpt(name, default) end local defaultOpts = { - autocd = false + autocd = false, + greeting = string.format([[Welcome to {magenta}Hilbish{reset}, {cyan}%s{reset}. +The nice lil shell for {blue}Lua{reset} fanatics! +]], hilbish.user) } for optsName, default in pairs(defaultOpts) do From 6eea5bce47646f27eaed44aa147f53429c0a1fd7 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 9 Jul 2022 17:54:21 -0400 Subject: [PATCH 3/5] feat: add motd (closes #185) --- CHANGELOG.md | 3 +++ nature/opts/init.lua | 3 ++- nature/opts/motd.lua | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 nature/opts/motd.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index efda87e..b3ab22b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,9 @@ having and using multiple runners. - Lua modules located in `hilbish.userDir.data .. '/hilbish/start'` (like `~/.local/share/hilbish/start/foo/init.lua`) will be ran on startup - `hilbish.init` hook, thrown after Hilbish has initialized Lua side +- Message of the day on startup (`hilbish.motd`), mainly intended as quick +small news pieces for releases. It is printed by default. To disable it, +set `hilbish.opts.motd` to false. ### Changed - **Breaking Change:** Upgraded to Lua 5.4. diff --git a/nature/opts/init.lua b/nature/opts/init.lua index d9de420..0b32f3f 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -23,7 +23,8 @@ local defaultOpts = { autocd = false, greeting = string.format([[Welcome to {magenta}Hilbish{reset}, {cyan}%s{reset}. The nice lil shell for {blue}Lua{reset} fanatics! -]], hilbish.user) +]], hilbish.user), + motd = true } for optsName, default in pairs(defaultOpts) do diff --git a/nature/opts/motd.lua b/nature/opts/motd.lua new file mode 100644 index 0000000..b22f5a2 --- /dev/null +++ b/nature/opts/motd.lua @@ -0,0 +1,13 @@ +local bait = require 'bait' +local lunacolors = require 'lunacolors' + +hilbish.motd = [[ +Hilbish 2.0 is a {red}major{reset} update! If your config doesn't work +anymore, that will definitely be why! A MOTD, very message, much day. +]] + +bait.catch('hilbish.init', function() + if hilbish.opts.motd then + print(lunacolors.format(hilbish.motd)) + end +end) From 60dd5f598a43c471e4b9cbb22886a6a0806ce99e Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 9 Jul 2022 18:38:57 -0400 Subject: [PATCH 4/5] docs: replace make with task on readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bb2ca29..bdb4dc9 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ If you're new to nix you should probably read up on how to do that [here](https: ## Manual Build ### Prerequisites - [Go 1.17+](https://go.dev) +- [Task](https://taskfile.dev/#/) ### Build First, clone Hilbish. The recursive is required, as some Lua libraries @@ -78,16 +79,16 @@ go get -d ./... To build, run: ``` -make dev +task ``` Or, if you want a stable branch, run these commands: ``` git checkout $(git describe --tags `git rev-list --tags --max-count=1`) -make build +task build ``` -After you did all that, run `sudo make install` to install Hilbish globally. +After you did all that, run `sudo task install` to install Hilbish globally. # Getting Started At startup, you should see a message which says to run a `guide` command. From 83a2ce38ea57da06ef731062804c67d5ef2c7a8a Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 9 Jul 2022 18:39:21 -0400 Subject: [PATCH 5/5] docs: remove getting started section on readme --- README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README.md b/README.md index bdb4dc9..86879d1 100644 --- a/README.md +++ b/README.md @@ -90,20 +90,6 @@ task build After you did all that, run `sudo task install` to install Hilbish globally. -# Getting Started -At startup, you should see a message which says to run a `guide` command. -This guide is a *very* simple and basic step through text of what Hilbish is -and where to find documentation. - -Documentation is primarily viewed via the in shell `doc` command. -Autogenerated function docs and general docs about other things are included -there, so be sure to read it. - -Using Hilbish is the same as using any other Linux shell, with an addition -that you can also run Lua. Hilbish can also act as an enhanced Lua REPL -via `hilbish.runnerMode 'lua'`. To switch back to normal, use -`hilbish.runnerMode 'hybrid'`. - # Contributing Any kind of contributions are welcome! Hilbish is very easy to contribute to. Read [CONTRIBUTING.md](CONTRIBUTING.md) as a guideline to doing so.