Skip to content

Commit

Permalink
feat: improve install
Browse files Browse the repository at this point in the history
  • Loading branch information
NonLogicalDev committed Feb 16, 2023
1 parent 5e353a3 commit cd14abf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before:
- go mod tidy
builds:
- main: ./cmd/goprompt
binary: frk
binary: goprompt
env:
- CGO_ENABLED=0
goos:
Expand Down
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,7 @@ And the main POC query/rendering logic is implemented in GO
## Install

```
$ eval "$(gimme 1.18.3)"
$ eval "$(gimme 1.20)"
$ make install
$ make setup >> ~/.zshrc
```

Assuming GoPrompt installed in `~/bin` and zsh func in `~/.local/share/zsh-funcs`

`make setup` will add the following to your `~/.zshrc`:

```
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
path+=( "$HOME/bin" )
fpath+=( "$HOME/.local/share/zsh-funcs" )
autoload -Uz promptinit
promptinit && prompt_asynczle_setup
# ------------------------------------------------------------------------------
$ goprompt install zsh.zshrc >> ~/.zshrc
```
50 changes: 31 additions & 19 deletions cmd/goprompt/cmdInstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,52 @@ package main

import (
"fmt"

goprompt "github.com/NonLogicalDev/shell.async-goprompt"
"github.com/spf13/cobra"
)

var installDesc = `
To install run the following:
$ goprompt install zsh.zshrc >> .zshrc
FILE options:
* zsh.zshrc
* zsh.plugin
`

var (
cmdInstall = &cobra.Command{
Use: "install",
Use: "install [FILE]",
Short: "install the integration",
Long: trim(installDesc),
Args: cobra.MinimumNArgs(1),
}
)

const (
_zshRc = "zshrc"
_zshPlugin = "zshplugin"
)

func init() {
cmdInstall.RunE = cmdInstallRun
}

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

func cmdInstallRun(command *cobra.Command, args []string) error {
fmt.Println(`
# SETUP:
# ------------------------------------------------------------------------------
# Assuming GoPrompt is installed in $(USR_BIN_DIR)
# and zsh func in $(USR_ZSH_DIR)
# ------------------------------------------------------------------------------
# $$ make setup >> ~/.zshrc"
# ------------------------------------------------------------------------------
# Add this to your ~/.zshenv
# ------------------------------------------------------------------------------
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
path+=( "$(USR_BIN_DIR)" )
fpath+=( "$(USR_ZSH_DIR)" )
autoload -Uz promptinit
promptinit && prompt_asynczle_setup
# ------------------------------------------------------------------------------
`)
var content string
switch args[0] {
case "zsh.zshrc":
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_install.zsh")
content = string(f)
case "zsh.plugin":
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_asynczle_setup.zsh")
content = string(f)
}
fmt.Println(content)
return nil
}
4 changes: 2 additions & 2 deletions cmd/goprompt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func debugLog(msg string, args ...[]interface{}) {
func init() {
cmd.AddCommand(cmdQuery)
cmd.AddCommand(cmdRender)
cmd.AddCommand(cmdInstall)
}

func main() {

err := cmd.ExecuteContext(bgctx)
if err != nil {
panic(err)
os.Exit(1)
}
}
6 changes: 6 additions & 0 deletions plugin/zsh/prompt_install.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# PROMPT_ASYNC_ZLE: ------------------------------------------------------------
if (($+commands[goprompt])); then
autoload -Uz promptinit
promptinit && eval "$(goprompt install zsh.plugin)"
fi
# ------------------------------------------------------------------------------
8 changes: 8 additions & 0 deletions static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package goprompt

import "embed"

var (
//go:embed plugin/zsh
ZSHPluginFiles embed.FS
)

0 comments on commit cd14abf

Please sign in to comment.