https://github.com/hashibuto/nilshell
Shell for golang which provides only the bare interface for processing a command
https://github.com/hashibuto/nilshell
cli go golang readline shell
Last synced: 4 months ago
JSON representation
Shell for golang which provides only the bare interface for processing a command
- Host: GitHub
- URL: https://github.com/hashibuto/nilshell
- Owner: hashibuto
- License: mit
- Created: 2022-12-02T06:20:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-29T03:22:12.000Z (over 1 year ago)
- Last Synced: 2025-09-19T00:02:08.401Z (9 months ago)
- Topics: cli, go, golang, readline, shell
- Language: Go
- Homepage:
- Size: 1.47 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: historymanager.go
- License: LICENSE
Awesome Lists containing this project
README
# nilshell
Command shell for golang which provides a minimal line editor and command processing loop. Here's what you get with NilShell:
- Line editor (type, insert, delete)
- Command history (up/down to navigate, load/export)
- Reverse search (simple pattern match, most recent history first)
- Tab completion hook
- Handling of terminal resize
What it doesn't do
- Any sort of argument parsing / tokenization
For a full CLI parser implementation using nilshell, check out [Commander](https://github.com/hashibuto/commander)
## Usage
```
import (
ns "github.com/hashibuto/nilshell"
)
config := ns.ReaderConfig{
CompletionFunction: func(beforeCursor string, afterCursor string, full string) *ns.Suggestions {
// This is where you would return tab completion suggestions based on the input before the cursor, perhaps after the
// cursor, or even the entire line buffer.
return &ns.Suggestions{
Total: 0
Items: []*ns.Suggestion{}
}
},
ProcessFunction: func(text string) error {
// text contains the command to be processed by your own command interpreter
return nil
}
// implement your own history manager if you want to persist history across multiple invocations, or use the default (nil)
HistoryManager: nil,
PromptFunction: func() string {
// Return a prompt with terminal escape chars to add style
return "$ "
},
Debug: false,
// enable the log file to dump debugging info to a tailable log file
LogFile: "",
}
r := NewReader(config)
// block until the process captures SIGINT or SIGTERM
r.ReadLoop()
```