Compare commits

...

5 Commits

Author SHA1 Message Date
TorchedSammy 6eea5bce47
feat: add motd (closes #185) 2022-07-09 17:54:21 -04:00
TorchedSammy a106f4aea0
refactor!: move hilbish.greeting to an opt (closes #184) 2022-07-09 17:15:13 -04:00
TorchedSammy 90ed12d551
feat: add hilbish.init hook (closes #186) 2022-07-09 17:04:50 -04:00
sammy e0694c8862
build!: replace make with task (#171)
* build!: replace make with task

allows easy windows building (besides literally go build)
down the line because getting make on windows is dumb
and even if you do it probably wouldnt work as intended
on there

(i also find task more intuitive for simple things)

* ci: use task in build workflow instead of make

* style: remove whitespace errors in task file

* docs: add task in changelog

* docs: fix link to task

* docs: change message for task notice
2022-07-09 11:44:53 -04:00
TorchedSammy d27ce26be0
feat: complete files plainly if tab query begins with quotes (workaround #183) 2022-07-09 10:45:42 -04:00
11 changed files with 109 additions and 44 deletions

View File

@ -26,8 +26,10 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: '1.17.7'
- name: Download Task
run: 'sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d'
- name: Build
run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} make
run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} ./bin/task
- uses: actions/upload-artifact@v2
if: matrix.goos == 'windows'
with:

View File

@ -9,8 +9,6 @@ local function doPrompt(fail)
))
end
print(lunacolors.format(hilbish.greeting))
doPrompt()
bait.catch('command.exit', function(code)

View File

@ -1,6 +1,10 @@
# 🎀 Changelog
## Unreleased
**NOTE:** Hilbish now uses [Task] insead of Make for builds.
[Task]: https://taskfile.dev/#/
### Added
- Inline hints, akin to fish and the others.
To make a handler for hint text, you can set the `hilbish.hinter` function.
@ -57,6 +61,10 @@ 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
- 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.
@ -72,12 +80,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

View File

@ -1,30 +0,0 @@
PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/share/hilbish
MY_GOFLAGS = -ldflags "-s -w"
all: dev
dev: MY_GOFLAGS = -ldflags "-s -w -X main.gitCommit=$(shell git rev-parse --short HEAD) -X main.gitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
dev: build
build:
go build $(MY_GOFLAGS)
install:
install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish"
mkdir -p "$(DESTDIR)$(LIBDIR)"
cp -r libs docs emmyLuaDocs nature .hilbishrc.lua "$(DESTDIR)$(LIBDIR)"
grep -qxF "$(DESTDIR)$(BINDIR)/hilbish" /etc/shells || echo "$(DESTDIR)$(BINDIR)/hilbish" >> /etc/shells
uninstall:
rm -vrf \
"$(DESTDIR)$(BINDIR)/hilbish" \
"$(DESTDIR)$(LIBDIR)"
sed -i '/hilbish/d' /etc/shells
clean:
go clean
.PHONY: all dev build install uninstall clean

36
Taskfile.yaml 100644
View File

@ -0,0 +1,36 @@
# https://taskfile.dev
version: '3'
vars:
PREFIX: '{{default "/usr" .PREFIX}}'
bindir__: '{{.PREFIX}}/bin'
BINDIR: '{{default .bindir__ .BINDIR}}'
libdir__: '{{.PREFIX}}/share/hilbish'
LIBDIR: '{{default .libdir__ .LIBDIR}}'
GOFLAGS: '-ldflags "-s -w"'
tasks:
default:
cmds:
- go build {{.GOFLAGS}}
vars:
GOFLAGS: '-ldflags "-s -w -X main.gitCommit=$(git rev-parse --short HEAD) -X main.gitBranch=$(git rev-parse --abbrev-ref HEAD)"'
build:
cmds:
- go build {{.GOFLAGS}}
install:
cmds:
- install -v -d "{{.DESTDIR}}{{.BINDIR}}/" && install -m 0755 -v hilbish "{{.DESTDIR}}{{.BINDIR}}/hilbish"
- mkdir -p "{{.DESTDIR}}{{.LIBDIR}}"
- cp -r libs docs emmyLuaDocs nature .hilbishrc.lua {{.DESTDIR}}{{.LIBDIR}}
- grep -qxF "{{.DESTDIR}}{{.BINDIR}}/hilbish" /etc/shells || echo "{{.DESTDIR}}{{.BINDIR}}/hilbish" >> /etc/shells
uninstall:
cmds:
- rm -vrf
"{{.DESTDIR}}{{.BINDIR}}/hilbish"
"{{.DESTDIR}}{{.LIBDIR}}"
- sed -i '/hilbish/d' /etc/shells

6
api.go
View File

@ -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.")

View File

@ -11,8 +11,34 @@ import (
rt "github.com/arnodel/golua/runtime"
)
func splitQuote(str string) []string {
split := []string{}
sb := &strings.Builder{}
quoted := false
for _, r := range str {
if r == '"' {
quoted = !quoted
sb.WriteRune(r)
} else if !quoted && r == ' ' {
split = append(split, sb.String())
sb.Reset()
} else {
sb.WriteRune(r)
}
}
if sb.Len() > 0 {
split = append(split, sb.String())
}
return split
}
func fileComplete(query, ctx string, fields []string) ([]string, string) {
return matchPath(query)
q := splitQuote(ctx)
return matchPath(q[len(q) - 1])
}
func binaryComplete(query, ctx string, fields []string) ([]string, string) {
@ -68,6 +94,8 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
}
func matchPath(query string) ([]string, string) {
oldQuery := query
query = strings.TrimPrefix(query, "\"")
var entries []string
var baseName string
@ -87,7 +115,9 @@ func matchPath(query string) ([]string, string) {
if file.IsDir() {
entry = entry + string(os.PathSeparator)
}
entry = escapeFilename(entry)
if !strings.HasPrefix(oldQuery, "\"") {
entry = escapeFilename(entry)
}
entries = append(entries, entry)
}
}

View File

@ -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))

View File

@ -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)

View File

@ -20,7 +20,11 @@ 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),
motd = true
}
for optsName, default in pairs(defaultOpts) do

View File

@ -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)