Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This completes bug IDs in bash and fish. I haven't gotten this to work in zsh. In fish, the bug titles are shown as completion label, and can be searched for. I don't know if/how other shells can show the completion label. Anyway, everything after the "\t" separator seems to be ignored. Part of #493
- Loading branch information
Showing
9 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package commands | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/MichaelMure/git-bug/cache" | ||
"github.com/MichaelMure/git-bug/query" | ||
) | ||
|
||
type validArgsFunction func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) | ||
|
||
func completeBugs(env *Env) validArgsFunction { | ||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
if err := loadBackend(env)(cmd, args); err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
defer func() { | ||
err := closeBackend(env)(cmd, args) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
}() | ||
|
||
q := query.NewQuery() | ||
allIds, err := env.backend.QueryBugs(q) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
|
||
bugExcerpt := make([]*cache.BugExcerpt, len(allIds)) | ||
for i, id := range allIds { | ||
bugExcerpt[i], err = env.backend.ResolveBugExcerpt(id) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
} | ||
|
||
completions := make([]string, len(allIds)) | ||
for i, id := range allIds { | ||
completions[i] = id.Human() + "\t" + bugExcerpt[i].Title | ||
} | ||
return completions, cobra.ShellCompDirectiveDefault | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters