Skip to content

Commit

Permalink
fix comp point greater than comp line size. fixes panic when getting…
Browse files Browse the repository at this point in the history
… tab completion for some users
  • Loading branch information
chriswalz committed Oct 14, 2020
1 parent 8d4829b commit 0b92c92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion a.MD
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ man page parsing + flag suggestions for all commands

git log --pretty=format:"* [%s](https://github.com/chriswalz/bit/commit/%H)" 09facd30..HEAD

deleting tags from local and origin is painful
deleting tags from local and origin is painful

COMP_POINT=25 COMP_LINE="bit status" bitcomplete
16 changes: 16 additions & 0 deletions bitcomplete/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@
package main

import (
"fmt"
"github.com/c-bata/go-prompt"
"github.com/chriswalz/bit/cmd"
"github.com/posener/complete/v2"
"github.com/posener/complete/v2/predict"
"github.com/thoas/go-funk"
"os"
"strconv"
"strings"
)

func main() {
compLine := os.Getenv("COMP_LINE")
compPoint := os.Getenv("COMP_POINT")
i, err := strconv.Atoi(compPoint)
if err != nil {
fmt.Println("COMP_LINE", compLine, "COMP_POINT", compPoint, "err:", err)
return
}
if i > len(compLine) {
err := os.Setenv("COMP_POINT", strconv.Itoa(len(compLine)))
if err != nil {
fmt.Println(err)
}
}

branchCompletion := &complete.Command{
Args: complete.PredictFunc(func(prefix string) []string {
Expand Down

0 comments on commit 0b92c92

Please sign in to comment.