Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neilotoole/shelleditor
Invoke the shell EDITOR like 'kubectl edit' does
https://github.com/neilotoole/shelleditor
editor go golang kubectl nano shell textpad vi vim
Last synced: 8 days ago
JSON representation
Invoke the shell EDITOR like 'kubectl edit' does
- Host: GitHub
- URL: https://github.com/neilotoole/shelleditor
- Owner: neilotoole
- License: apache-2.0
- Created: 2023-04-22T14:52:11.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-24T19:31:17.000Z (about 1 year ago)
- Last Synced: 2023-09-24T21:46:25.423Z (about 1 year ago)
- Topics: editor, go, golang, kubectl, nano, shell, textpad, vi, vim
- Language: Go
- Homepage:
- Size: 85.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shelleditor
Invoke the shell `EDITOR` like `kubectl edit` does.This code is lifted from [kubectl](https://github.com/kubernetes/kubectl/tree/master/pkg/cmd/util/editor).
Thanks lads.Why not import the `kubectl` code directly? It has tons of dependencies that are not needed
for this simple task. The codebase has been edited to import fewer packages,
and those that are imported are mostly copied to the `/pkg` dir.## Usage
Import via the normal mechanism.
```shell
go get -u github.com/neilotoole/shelleditor
```Note that because `shellescape` supports the stdlib `slog` logger,
so it requires Go 1.21 or greater.## Example program
There's an example program in [`cmd/shelleditor`](https://github.com/neilotoole/shelleditor/blob/master/cmd/shelleditor/main.go).
```shell
$ go install github.com/neilotoole/shelleditor/cmd/shelleditor
$ shelleditor hello.txt
```It's very simple:
```go
package mainimport (
"fmt"
"log/slog"
"os""github.com/neilotoole/shelleditor"
)func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: shelleditor PATH")
os.Exit(1)
}// Set logger... you can usually ignore this. When not
// set, log output is discarded.
shelleditor.SetLogger(slog.Default())ed := shelleditor.NewDefaultEditor("EDITOR")
if err := ed.Launch(os.Args[1]); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
```## Alternatives
- [th/go-editor](https://github.com/tj/go-editor)