Skip to content

Commit

Permalink
feat: improve install experience
Browse files Browse the repository at this point in the history
  • Loading branch information
NonLogicalDev committed Feb 15, 2023
1 parent ba3beb3 commit 93c49f1
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
eval $(gimme 1.18.3)
eval $(gimme 1.20)
PATH_add dist
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
.vscode
goprompt
dist
28 changes: 28 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
before:
hooks:
- go mod tidy
builds:
- main: ./cmd/goprompt
binary: frk
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format: binary
wrap_in_directory: false

checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"

# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export prefix?=$(HOME)/.local
export bindir?=$(prefix)/bin

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))

Expand All @@ -6,13 +9,22 @@ ZSH_PROMPT_SETUP_SCRIPT := $(CURRENT_DIR)/plugin/zsh/prompt_asynczle_setup.zsh
USR_BIN_DIR := $(HOME)/bin
USR_ZSH_DIR := $(HOME)/.local/share/zsh-funcs

.PHONY: publish
publish:
goreleaser release --rm-dist

.PHONY: release
release:
goreleaser release --rm-dist --snapshot --skip-publish

.PHONY: build
build:
go build -o "goprompt" ./cmd/goprompt
goreleaser build --rm-dist --snapshot --single-target --output dist/goprompt

.PHONY: install
install:
install: build
mkdir -p "$(USR_BIN_DIR)"
go build -o "$(USR_BIN_DIR)/goprompt" ./cmd/goprompt
cp dist/goprompt "$(USR_BIN_DIR)/goprompt"
mkdir -p "$(USR_ZSH_DIR)"
cp "$(ZSH_PROMPT_SETUP_SCRIPT)" "$(USR_ZSH_DIR)/prompt_asynczle_setup"
$(MAKE) setup
Expand Down Expand Up @@ -42,3 +54,6 @@ try: install
@echo '>> FOR DEVELOPMENT ONLY <<'
ZSH_DISABLE_PROMPT=Y ZSH_EXTRA_SOURCE="$(ZSH_PROMPT_SETUP_SCRIPT)" zsh

.PHONY: clean
clean:
rm -rf dist
41 changes: 41 additions & 0 deletions cmd/goprompt/cmdInstall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"github.com/spf13/cobra"
)

var (
cmdInstall = &cobra.Command{
Use: "install",
Short: "install the integration",
}
)

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
# ------------------------------------------------------------------------------
`)
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/NonLogicalDev/shell.async-goprompt

go 1.18
go 1.20

require (
github.com/gookit/color v1.5.1
Expand Down
2 changes: 2 additions & 0 deletions plugin/zsh/prompt_asynczle_setup.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ __zle_async_dispatch() {
__zle_async_detach "$OLD_ZLE_FD" 2>/dev/null
fi

local ZLE_FD

# Create File Descriptor and attach to async command
exec {ZLE_FD}< <( "${command[@]}" )

Expand Down

0 comments on commit 93c49f1

Please sign in to comment.