Compare commits

..

No commits in common. "c329d21e7d6d3c072d14f0a89322fef539bd22bc" and "4e244e141f561eb336b0ca430ebef6aef4e5a086" have entirely different histories.

5 changed files with 30 additions and 71 deletions

View File

@ -2,46 +2,6 @@
This is the changelog for the Hilbish shell made in Go and Lua. This is the changelog for the Hilbish shell made in Go and Lua.
## [0.7.1] - 2021-11-22
### Fixed
- Tab complete absolute paths to binaries properly
- Allow execution of absolute paths to binaries (https://github.com/Rosettea/Hilbish/commit/06272778f85dad04e0e7abffc78a5b9b0cebd067 regression)
## [0.7.0] - 2021-11-22
### Added
- `hilbish.interactive` and `hilbish.login` properties to figure out if Hilbish is interactive or a login shell, respectively.
- `hilbish.read` function to take input more elegantly than Lua's `io.read`
- Tab Completion Enhancements
- A new tab complete API has been added. It is the single `complete` function which takes a "scope" (example: `command.<cmdname>`) and a callback which is
expected to return a table. Users can now add custom completions for specific commands.
An example is:
```lua
complete('command.git', function()
return {
'add',
'version',
commit = {
'--message',
'--verbose',
'<file>'
}
}
end)
```
For `git`, Hilbish will complete commands add, version and commit. For the commit subcommand, it will complete the flags and/or files which `<file>` is used to represent.
- Hilbish will now complete binaries in $PATH, or any executable to a path (like `./` or `../`)
- Files with spaces will be automatically put in quotes and completions will work for them now.
- `prependPath` function (#81)
- Signal hooks (#80)
- This allows scripts to add their own way of handling terminal resizes (if you'd need that) or Ctrl-C
- Module properties (like `hilbish.ver`) are documented with the `doc` command.
- Document bait hooks
### Fixed
- The prompt won't come up on terminal resize anymore.
- `appendPath` should work properly on Windows.
- A panic when a commander has an error has been fixed.
## [0.6.1] - 2021-10-21 ## [0.6.1] - 2021-10-21
### Fixed ### Fixed
- Require paths now use the `dataDir` variable so there is no need to change it anymore unless you want to add more paths - Require paths now use the `dataDir` variable so there is no need to change it anymore unless you want to add more paths
@ -289,8 +249,6 @@ This input for example will prompt for more input to complete:
First "stable" release of Hilbish. First "stable" release of Hilbish.
[0.7.1]: https://github.com/Rosettea/Hilbish/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/Rosettea/Hilbish/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/Rosettea/Hilbish/compare/v0.6.0...v0.6.1 [0.6.1]: https://github.com/Rosettea/Hilbish/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/Rosettea/Hilbish/compare/v0.5.1...v0.6.0 [0.6.0]: https://github.com/Rosettea/Hilbish/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/Rosettea/Hilbish/compare/v0.5.0...v0.5.1 [0.5.1]: https://github.com/Rosettea/Hilbish/compare/v0.5.0...v0.5.1

View File

@ -2,12 +2,6 @@ alias(cmd, orig) > Sets an alias of `orig` to `cmd`
appendPath(dir) > Appends `dir` to $PATH appendPath(dir) > Appends `dir` to $PATH
complete(scope, cb) > Registers a completion handler for `scope`.
A `scope` is currently only expected to be `command.<cmd>`,
replacing <cmd> with the name of the command (for example `command.git`).
`cb` must be a function that returns a table of the entries to complete.
Nested tables will be used as sub-completions.
exec(cmd) > Replaces running hilbish with `cmd` exec(cmd) > Replaces running hilbish with `cmd`
goro(fn) > Puts `fn` in a goroutine goro(fn) > Puts `fn` in a goroutine
@ -16,8 +10,6 @@ interval(cb, time) > Runs the `cb` function every `time` milliseconds
multiprompt(str) > Changes the continued line prompt to `str` multiprompt(str) > Changes the continued line prompt to `str`
prependPath(dir) > Prepends `dir` to $PATH
prompt(str) > Changes the shell prompt to `str` prompt(str) > Changes the shell prompt to `str`
There are a few verbs that can be used in the prompt text. There are a few verbs that can be used in the prompt text.
These will be formatted and replaced with the appropriate values. These will be formatted and replaced with the appropriate values.

36
rl.go
View File

@ -25,7 +25,7 @@ func NewLineReader(prompt string) *LineReader {
var completions []string var completions []string
// trim whitespace from ctx // trim whitespace from ctx
ctx = strings.TrimLeft(ctx, " ") ctx = strings.TrimLeft(ctx, " ")
fields := strings.Split(ctx, " ") fields, ctx := splitInput(ctx)
if len(fields) == 0 { if len(fields) == 0 {
return nil return nil
} }
@ -44,21 +44,37 @@ func NewLineReader(prompt string) *LineReader {
} }
if len(fields) == 1 { if len(fields) == 1 {
fileCompletions := append(completions, readline.FilenameCompleter(query, ctx)...) prefixes := []string{"./", "../"}
// filter out executables for _, prefix := range prefixes {
for _, f := range fileCompletions { if strings.HasPrefix(query, prefix) {
name := strings.Replace(f, "~", homedir, 1) if matches, err := filepath.Glob(query + "*"); err == nil {
if info, err := os.Stat(name); err == nil && info.Mode().Perm() & 0100 == 0 { for _, match := range matches {
if info, err := os.Stat(match); err == nil && info.Mode().Perm() & 0100 == 0 {
continue continue
} }
completions = append(completions, f) name := filepath.Base(match)
completions = append(completions, name)
}
}
if len(completions) == 1 {
// we have add the base dir of query since the completion entries are basename
// why? so readline will display just that
// and we want to complete the full path when its the only completion entry
// query will be incomplete so adding it will be broken
// also Dir doesn't have a trailing slash so we need to filepath join
// to account to windows
// AND ANOTHER THING is it returns . if the arg is ./ and Join will
// ignore that so we have to check and just add the prefix instead
if prefix != "./" {
completions[0] = filepath.Join(filepath.Dir(query), completions[0])
} else {
completions[0] = prefix + completions[0]
}
} }
if len(completions) != 0 {
return completions return completions
} }
}
// filter out executables, but in path
for _, dir := range filepath.SplitList(os.Getenv("PATH")) { for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
// print dir to stderr for debugging // print dir to stderr for debugging
// search for an executable which matches our query string // search for an executable which matches our query string

View File

@ -166,13 +166,6 @@ func execCommand(cmd string) error {
// custom lookpath function so we know if a command is found *and* has execute permission // custom lookpath function so we know if a command is found *and* has execute permission
func lookpath(file string) error { func lookpath(file string) error {
skip := []string{"./", "/", "../", "~/"}
for _, s := range skip {
if strings.HasPrefix(file, s) {
err := findExecutable(file)
return err
}
}
for _, dir := range filepath.SplitList(os.Getenv("PATH")) { for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
path := filepath.Join(dir, file) path := filepath.Join(dir, file)
err := findExecutable(path) err := findExecutable(path)

View File

@ -2,7 +2,7 @@ package main
// String vars that are free to be changed at compile time // String vars that are free to be changed at compile time
var ( var (
version = "v0.7.1" version = "v0.7.0"
defaultConfDir = "" // ~ will be substituted for home, path for user's default config defaultConfDir = "" // ~ will be substituted for home, path for user's default config
defaultHistDir = "" defaultHistDir = ""
commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'" commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'"