Skip to content

Commit cd14abf

Browse files
committed
feat: improve install
1 parent 5e353a3 commit cd14abf

File tree

6 files changed

+50
-37
lines changed

6 files changed

+50
-37
lines changed

.goreleaser.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ before:
33
- go mod tidy
44
builds:
55
- main: ./cmd/goprompt
6-
binary: frk
6+
binary: goprompt
77
env:
88
- CGO_ENABLED=0
99
goos:

README.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,7 @@ And the main POC query/rendering logic is implemented in GO
2424
## Install
2525

2626
```
27-
$ eval "$(gimme 1.18.3)"
27+
$ eval "$(gimme 1.20)"
2828
$ make install
29-
$ make setup >> ~/.zshrc
30-
```
31-
32-
Assuming GoPrompt installed in `~/bin` and zsh func in `~/.local/share/zsh-funcs`
33-
34-
`make setup` will add the following to your `~/.zshrc`:
35-
36-
```
37-
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
38-
path+=( "$HOME/bin" )
39-
fpath+=( "$HOME/.local/share/zsh-funcs" )
40-
autoload -Uz promptinit
41-
promptinit && prompt_asynczle_setup
42-
# ------------------------------------------------------------------------------
29+
$ goprompt install zsh.zshrc >> ~/.zshrc
4330
```

cmd/goprompt/cmdInstall.go

+31-19
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,52 @@ package main
22

33
import (
44
"fmt"
5+
6+
goprompt "github.com/NonLogicalDev/shell.async-goprompt"
57
"github.com/spf13/cobra"
68
)
79

10+
var installDesc = `
11+
To install run the following:
12+
13+
$ goprompt install zsh.zshrc >> .zshrc
14+
15+
FILE options:
16+
17+
* zsh.zshrc
18+
* zsh.plugin
19+
`
20+
821
var (
922
cmdInstall = &cobra.Command{
10-
Use: "install",
23+
Use: "install [FILE]",
1124
Short: "install the integration",
25+
Long: trim(installDesc),
26+
Args: cobra.MinimumNArgs(1),
1227
}
1328
)
1429

30+
const (
31+
_zshRc = "zshrc"
32+
_zshPlugin = "zshplugin"
33+
)
34+
1535
func init() {
1636
cmdInstall.RunE = cmdInstallRun
1737
}
1838

1939
// TODO: bundle in the plugin directory, and provide a way to extract it into users directory of choice.
2040

2141
func cmdInstallRun(command *cobra.Command, args []string) error {
22-
fmt.Println(`
23-
# SETUP:
24-
# ------------------------------------------------------------------------------
25-
# Assuming GoPrompt is installed in $(USR_BIN_DIR)
26-
# and zsh func in $(USR_ZSH_DIR)
27-
# ------------------------------------------------------------------------------
28-
# $$ make setup >> ~/.zshrc"
29-
# ------------------------------------------------------------------------------
30-
# Add this to your ~/.zshenv
31-
# ------------------------------------------------------------------------------
32-
33-
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
34-
path+=( "$(USR_BIN_DIR)" )
35-
fpath+=( "$(USR_ZSH_DIR)" )
36-
autoload -Uz promptinit
37-
promptinit && prompt_asynczle_setup
38-
# ------------------------------------------------------------------------------
39-
`)
42+
var content string
43+
switch args[0] {
44+
case "zsh.zshrc":
45+
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_install.zsh")
46+
content = string(f)
47+
case "zsh.plugin":
48+
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_asynczle_setup.zsh")
49+
content = string(f)
50+
}
51+
fmt.Println(content)
4052
return nil
4153
}

cmd/goprompt/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func debugLog(msg string, args ...[]interface{}) {
3636
func init() {
3737
cmd.AddCommand(cmdQuery)
3838
cmd.AddCommand(cmdRender)
39+
cmd.AddCommand(cmdInstall)
3940
}
4041

4142
func main() {
42-
4343
err := cmd.ExecuteContext(bgctx)
4444
if err != nil {
45-
panic(err)
45+
os.Exit(1)
4646
}
4747
}

plugin/zsh/prompt_install.zsh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
2+
if (($+commands[goprompt])); then
3+
autoload -Uz promptinit
4+
promptinit && eval "$(goprompt install zsh.plugin)"
5+
fi
6+
# ------------------------------------------------------------------------------

static.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package goprompt
2+
3+
import "embed"
4+
5+
var (
6+
//go:embed plugin/zsh
7+
ZSHPluginFiles embed.FS
8+
)

0 commit comments

Comments
 (0)