Skip to content

Commit

Permalink
add interactive prompt mode (keep prompt running)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswalz-bg committed Apr 15, 2021
1 parent 559852d commit 440a72e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [X] single binary
- [X] much more suggestions available! (Roughly 10x more)
- [X] Install with homebrew & macports
- [X] Interactive prompt with env variable: BIT_INTERACTIVE=true

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

## Changelog
v1.1
- [X] enhancement: enable interactive prompt (keep bit running) with env variable: BIT_INTERACTIVE=true

v1.0
- [X] enhancement: significantly more autocompletions
- [X] enhancement: use fuzzy search for branch suggestions
Expand Down
49 changes: 29 additions & 20 deletions cmd/bit_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,39 @@ var BitCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
suggestionTree, bitCmdMap := CreateSuggestionMap(cmd)

resp := SuggestionPrompt("> bit ", shellCommandCompleter(suggestionTree))
subCommand := resp
if subCommand == "" {
return
repeat := os.Getenv("BIT_INTERACTIVE") == "TRUE"
repeatAmount := 1
if repeat {
repeatAmount = 5000
}
if strings.Index(resp, " ") > 0 {
subCommand = subCommand[0:strings.Index(resp, " ")]
}
parsedArgs, err := parseCommandLine(resp)
if err != nil {
log.Debug().Err(err).Send()
return
}
if bitCmdMap[subCommand] == nil {
yes := HijackGitCommandOccurred(parsedArgs, suggestionTree, cmd.Version)
if yes {


for i := repeatAmount; i > 0; i-- {
resp := SuggestionPrompt("> bit ", shellCommandCompleter(suggestionTree))
subCommand := resp
if subCommand == "" {
return
}
RunGitCommandWithArgs(parsedArgs)
return
}
if strings.Index(resp, " ") > 0 {
subCommand = subCommand[0:strings.Index(resp, " ")]
}
parsedArgs, err := parseCommandLine(resp)
if err != nil {
log.Debug().Err(err).Send()
continue
}
if bitCmdMap[subCommand] == nil {
yes := HijackGitCommandOccurred(parsedArgs, suggestionTree, cmd.Version)
if yes {
continue
}
RunGitCommandWithArgs(parsedArgs)
continue
}

cmd.SetArgs(parsedArgs)
cmd.Execute()
cmd.SetArgs(parsedArgs)
cmd.Execute()
}
},
}

Expand Down

0 comments on commit 440a72e

Please sign in to comment.