Skip to content

Commit 440a72e

Browse files
committed
add interactive prompt mode (keep prompt running)
1 parent 559852d commit 440a72e

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [X] single binary
3333
- [X] much more suggestions available! (Roughly 10x more)
3434
- [X] Install with homebrew & macports
35+
- [X] Interactive prompt with env variable: BIT_INTERACTIVE=true
3536

3637
--- **Coming Soon** ---
3738
- bit anticipates when you'll need to type git status and will display it proactively
@@ -163,6 +164,9 @@ Thanks to [Gitless](https://gitless.com/), [git-extras](https://github.com/tj/gi
163164
- https://blog.csdn.net/a419240016/article/details/109178001
164165

165166
## Changelog
167+
v1.1
168+
- [X] enhancement: enable interactive prompt (keep bit running) with env variable: BIT_INTERACTIVE=true
169+
166170
v1.0
167171
- [X] enhancement: significantly more autocompletions
168172
- [X] enhancement: use fuzzy search for branch suggestions

cmd/bit_cmd.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,39 @@ var BitCmd = &cobra.Command{
2323
Run: func(cmd *cobra.Command, args []string) {
2424
suggestionTree, bitCmdMap := CreateSuggestionMap(cmd)
2525

26-
resp := SuggestionPrompt("> bit ", shellCommandCompleter(suggestionTree))
27-
subCommand := resp
28-
if subCommand == "" {
29-
return
26+
repeat := os.Getenv("BIT_INTERACTIVE") == "TRUE"
27+
repeatAmount := 1
28+
if repeat {
29+
repeatAmount = 5000
3030
}
31-
if strings.Index(resp, " ") > 0 {
32-
subCommand = subCommand[0:strings.Index(resp, " ")]
33-
}
34-
parsedArgs, err := parseCommandLine(resp)
35-
if err != nil {
36-
log.Debug().Err(err).Send()
37-
return
38-
}
39-
if bitCmdMap[subCommand] == nil {
40-
yes := HijackGitCommandOccurred(parsedArgs, suggestionTree, cmd.Version)
41-
if yes {
31+
32+
33+
for i := repeatAmount; i > 0; i-- {
34+
resp := SuggestionPrompt("> bit ", shellCommandCompleter(suggestionTree))
35+
subCommand := resp
36+
if subCommand == "" {
4237
return
4338
}
44-
RunGitCommandWithArgs(parsedArgs)
45-
return
46-
}
39+
if strings.Index(resp, " ") > 0 {
40+
subCommand = subCommand[0:strings.Index(resp, " ")]
41+
}
42+
parsedArgs, err := parseCommandLine(resp)
43+
if err != nil {
44+
log.Debug().Err(err).Send()
45+
continue
46+
}
47+
if bitCmdMap[subCommand] == nil {
48+
yes := HijackGitCommandOccurred(parsedArgs, suggestionTree, cmd.Version)
49+
if yes {
50+
continue
51+
}
52+
RunGitCommandWithArgs(parsedArgs)
53+
continue
54+
}
4755

48-
cmd.SetArgs(parsedArgs)
49-
cmd.Execute()
56+
cmd.SetArgs(parsedArgs)
57+
cmd.Execute()
58+
}
5059
},
5160
}
5261

0 commit comments

Comments
 (0)