Skip to content

Commit 1dc52b3

Browse files
committed
clean: prepare for a proper user-friendly release
* Improve install procedure * Cleanup documentation * Get rid of homebrew Async Task Dispatcher in favor of `conc`
1 parent cd14abf commit 1dc52b3

File tree

8 files changed

+134
-136
lines changed

8 files changed

+134
-136
lines changed

Makefile

-28
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,6 @@ build:
2525
install: build
2626
mkdir -p "$(USR_BIN_DIR)"
2727
cp dist/goprompt "$(USR_BIN_DIR)/goprompt"
28-
mkdir -p "$(USR_ZSH_DIR)"
29-
cp "$(ZSH_PROMPT_SETUP_SCRIPT)" "$(USR_ZSH_DIR)/prompt_asynczle_setup"
30-
$(MAKE) setup
31-
32-
.PHONY: setup
33-
setup:
34-
@echo '# SETUP:' >&2
35-
@echo '# ------------------------------------------------------------------------------' >&2
36-
@echo '# Assuming GoPrompt installed in $(USR_BIN_DIR)' >&2
37-
@echo '# and zsh func in $(USR_ZSH_DIR)' >&2
38-
@echo '# ------------------------------------------------------------------------------' >&2
39-
@echo "# $$ make setup >> ~/.zshrc" >&2
40-
@echo '# ------------------------------------------------------------------------------' >&2
41-
@echo "# Add this to your ~/.zshenv" >&2
42-
@echo '# ------------------------------------------------------------------------------' >&2
43-
@echo ''
44-
@echo '# PROMPT_ASYNC_ZLE: ------------------------------------------------------------'
45-
@echo 'path+=( "$(USR_BIN_DIR)" )'
46-
@echo 'fpath+=( "$(USR_ZSH_DIR)" )'
47-
@echo 'autoload -Uz promptinit'
48-
@echo 'promptinit && prompt_asynczle_setup'
49-
@echo '# ------------------------------------------------------------------------------'
50-
51-
.PHONY: try
52-
try: install
53-
@echo '>> THIS NEEDS EXTRA CONFIG <<'
54-
@echo '>> FOR DEVELOPMENT ONLY <<'
55-
ZSH_DISABLE_PROMPT=Y ZSH_EXTRA_SOURCE="$(ZSH_PROMPT_SETUP_SCRIPT)" zsh
5628

5729
.PHONY: clean
5830
clean:

cmd/goprompt/cmdInstall.go

+44-18
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,77 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strings"
58

69
goprompt "github.com/NonLogicalDev/shell.async-goprompt"
10+
"github.com/kballard/go-shellquote"
711
"github.com/spf13/cobra"
812
)
913

10-
var installDesc = `
11-
To install run the following:
14+
var cmdInstallHelpLong = `
15+
# To install run the following:
1216
13-
$ goprompt install zsh.zshrc >> .zshrc
17+
$ goprompt install zsh >> .zshrc
1418
15-
FILE options:
19+
# [FILE] options:
1620
17-
* zsh.zshrc
21+
* zsh
1822
* zsh.plugin
1923
`
2024

25+
const defaultContent = `
26+
# To try for just this session run the following:
27+
28+
$ eval "$({{goprompt}} install zsh)"
29+
30+
# To install run the following:
31+
32+
$ {{goprompt}} install zsh >> .zshrc
33+
`
34+
2135
var (
2236
cmdInstall = &cobra.Command{
2337
Use: "install [FILE]",
24-
Short: "install the integration",
25-
Long: trim(installDesc),
26-
Args: cobra.MinimumNArgs(1),
38+
Short: "print out the shell script to setup prompt",
39+
Long: trim(cmdInstallHelpLong),
2740
}
2841
)
2942

30-
const (
31-
_zshRc = "zshrc"
32-
_zshPlugin = "zshplugin"
33-
)
34-
3543
func init() {
3644
cmdInstall.RunE = cmdInstallRun
3745
}
3846

39-
// TODO: bundle in the plugin directory, and provide a way to extract it into users directory of choice.
47+
func replacePlaceholders(content string) string {
48+
goPromptExec := os.Args[0]
49+
if strings.Contains(goPromptExec, "/") {
50+
if fullPath, err := filepath.Abs(goPromptExec); err == nil {
51+
goPromptExec = fullPath
52+
}
53+
}
54+
goPromptExec = shellquote.Join(goPromptExec)
55+
content = strings.ReplaceAll(content, "{{goprompt}}", goPromptExec)
56+
content = strings.ReplaceAll(content, "${GOPROMPT}", goPromptExec)
57+
return content
58+
}
4059

4160
func cmdInstallRun(command *cobra.Command, args []string) error {
61+
argFile := ""
62+
if len(args) > 0 {
63+
argFile = args[0]
64+
}
65+
4266
var content string
43-
switch args[0] {
44-
case "zsh.zshrc":
67+
switch argFile {
68+
case "zsh":
4569
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_install.zsh")
46-
content = string(f)
70+
content = replacePlaceholders(string(f))
4771
case "zsh.plugin":
4872
f, _ := goprompt.ZSHPluginFiles.ReadFile("plugin/zsh/prompt_asynczle_setup.zsh")
49-
content = string(f)
73+
content = replacePlaceholders(string(f))
74+
default:
75+
content = replacePlaceholders(defaultContent)
5076
}
5177
fmt.Println(content)
5278
return nil

cmd/goprompt/cmdQuery.go

+31-45
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func init() {
3838
cmdQuery.RunE = cmdQueryRun
3939
}
4040

41+
func mkWgPool() pool.ContextPool {
42+
return *pool.New().WithContext(bgctx)
43+
}
44+
4145
const (
4246
_partStatus = "st"
4347
_partTimestamp = "ts"
@@ -64,21 +68,17 @@ const (
6468
_partVcsLogAhead = "vcs_log_ahead"
6569
_partVcsLogBehind = "vcs_log_behind"
6670

67-
_partVcsStg = "stg"
68-
_partVcsStgQlen = "stg_qlen"
69-
_partVcsStgQpos = "stg_qpos"
70-
_partVcsStgTop = "stg_top"
71-
_partVcsStgDirty = "stg_dirty"
71+
_partVcsStg = "vcs_git_stg"
72+
_partVcsStgQlen = "vcs_git_stg_qlen"
73+
_partVcsStgQpos = "vcs_git_stg_qpos"
74+
_partVcsStgTop = "vcs_git_stg_top"
75+
_partVcsStgDirty = "vcs_git_stg_dirty"
7276

73-
_partVcsGitIdxTotal = "git_idx_total"
74-
_partVcsGitIdxIncluded = "git_idx_incl"
75-
_partVcsGitIdxExcluded = "git_idx_excl"
77+
_partVcsGitIdxTotal = "vcs_git_idx_total"
78+
_partVcsGitIdxIncluded = "vcs_git_idx_incl"
79+
_partVcsGitIdxExcluded = "vcs_git_idx_excl"
7680
)
7781

78-
func timeFMT(ts time.Time) string {
79-
return ts.Format("15:04:05 01/02/06")
80-
}
81-
8282
func handleQUIT() context.CancelFunc {
8383
sig := make(chan os.Signal, 1)
8484
signal.Notify(sig, os.Interrupt, os.Kill, syscall.SIGTERM)
@@ -134,7 +134,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
134134
}()
135135
}
136136

137-
tasks := pool.New().WithContext(bgctx)
137+
tasks := mkWgPool()
138138
defer func() {
139139
tasks.Wait()
140140
printPart("done", "ok")
@@ -215,7 +215,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
215215
})
216216

217217
tasks.Go(func(context.Context) error {
218-
subTasks := new(AsyncTaskDispatcher)
218+
subTasks := mkWgPool()
219219
defer subTasks.Wait()
220220

221221
if _, err := stringExec("git", "rev-parse", "--show-toplevel"); err == nil {
@@ -224,33 +224,35 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
224224
return nil
225225
}
226226

227-
subTasks.Dispatch(func() {
227+
subTasks.Go(func(ctx context.Context) error {
228228
if branch, err := stringExec("git", "branch", "--show-current"); err == nil {
229229
branch = trim(branch)
230230
if len(branch) > 0 {
231231
printPart(_partVcsBranch, trim(branch))
232-
return
232+
return nil
233233
}
234234
}
235235

236236
if branch, err := stringExec("git", "name-rev", "--name-only", "HEAD"); err == nil {
237237
branch = trim(branch)
238238
if len(branch) > 0 {
239239
printPart(_partVcsBranch, trim(branch))
240-
return
240+
return nil
241241
}
242242
}
243+
244+
return nil
243245
})
244246

245-
subTasks.Dispatch(func() {
247+
subTasks.Go(func(context.Context) error {
246248
status, err := stringExec("git", "status", "--porcelain")
247249
if err != nil {
248-
return
250+
return nil
249251
}
250252

251253
if len(status) == 0 {
252254
printPart(_partVcsDirty, 0)
253-
return
255+
return nil
254256
}
255257

256258
printPart(_partVcsDirty, 1)
@@ -281,9 +283,11 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
281283
printPart(_partVcsGitIdxTotal, fTotal)
282284
printPart(_partVcsGitIdxIncluded, fInIndex)
283285
printPart(_partVcsGitIdxExcluded, fOutOfIndex)
286+
287+
return nil
284288
})
285289

286-
subTasks.Dispatch(func() {
290+
subTasks.Go(func(context.Context) error {
287291
if status, err := stringExec("git", "rev-list", "--left-right", "--count", "HEAD...@{u}"); err == nil {
288292
parts := strings.SplitN(status, "\t", 2)
289293
if len(parts) < 2 {
@@ -293,6 +297,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
293297
printPart(_partVcsLogAhead, parts[0])
294298
printPart(_partVcsLogBehind, parts[1])
295299
}
300+
return nil
296301
})
297302

298303
return nil
@@ -301,8 +306,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
301306
tasks.Go(func(context.Context) error {
302307
var err error
303308

304-
subTasks := new(AsyncTaskDispatcher)
305-
defer subTasks.Wait()
309+
subTasks := mkWgPool()
306310

307311
var stgSeriesLen string
308312
if stgSeriesLen, err = stringExec("stg", "series", "-c"); err == nil {
@@ -312,10 +316,11 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
312316
return nil
313317
}
314318

315-
subTasks.Dispatch(func() {
319+
subTasks.Go(func(context.Context) error {
316320
if stgSeriesPos, err := stringExec("stg", "series", "-cA"); err == nil {
317321
printPart(_partVcsStgQpos, stgSeriesPos)
318322
}
323+
return nil
319324
})
320325

321326
var stgPatchTop string
@@ -325,7 +330,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
325330
return nil
326331
}
327332

328-
subTasks.Dispatch(func() {
333+
subTasks.Go(func(context.Context) error {
329334
gitSHA, _ := stringExec("stg", "id")
330335
stgSHA, _ := stringExec("stg", "id", stgPatchTop)
331336

@@ -334,6 +339,7 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
334339
} else {
335340
printPart(_partVcsStgDirty, 0)
336341
}
342+
return nil
337343
})
338344

339345
return nil
@@ -342,26 +348,6 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
342348
return nil
343349
}
344350

345-
func moduleFindProcessChain() ([]ps.Process, error) {
346-
psPTR := os.Getpid()
347-
var pidChain []ps.Process
348-
349-
for {
350-
if psPTR == 0 {
351-
break
352-
}
353-
psInfo, err := ps.FindProcess(psPTR)
354-
if err != nil {
355-
return nil, err
356-
}
357-
pidChain = append(pidChain, psInfo)
358-
psPTR = psInfo.PPid()
359-
}
360-
361-
return pidChain, nil
362-
}
363-
364-
365351
func startPrinter() (func(), func(name string, value interface{})) {
366352
debugLog("query-printer: start")
367353
defer debugLog("query-printer: stop")

0 commit comments

Comments
 (0)