-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support tab completions in the shell
* Basic shell completion * Skeleton for customizing klog command completions * Custom completion generator that lists *.klg files and klog bookmarks * Command completions for bookmarks commands * Switch to patched `kongplete` module * Add dedicated command and restructure * Setup hidden alias * Include more detailed setup instructions * Rename file * Naming Co-authored-by: Steve M. Kim <[email protected]>
- Loading branch information
Showing
11 changed files
with
133 additions
and
30 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
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,22 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/jotaen/klog/src/app" | ||
) | ||
|
||
type Completion struct{} | ||
|
||
func (c *Completion) Help() string { | ||
return "The printed shell code is for instructing your shell to use tab completions for klog. " + | ||
"Place the code into your shell initialization file, e.g. `~/.bashrc`. " + | ||
"You can either paste it verbatim, or you source it dynamically via `. <(klog completion)`." | ||
} | ||
|
||
func (c *Completion) Run(ctx app.Context) error { | ||
completion, err := ctx.Completion() | ||
if err != nil { | ||
return err | ||
} | ||
ctx.Print(completion) | ||
return nil | ||
} |
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
File renamed without changes.
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,29 @@ | ||
package klog | ||
|
||
import ( | ||
"github.com/jotaen/klog/src/app" | ||
"github.com/posener/complete" | ||
) | ||
|
||
func predictBookmarks(ctx app.Context) complete.Predictor { | ||
thunk := func() []string { | ||
names := make([]string, 0) | ||
bookmarksCollection, err := ctx.ReadBookmarks() | ||
if err != nil { | ||
return names | ||
} | ||
for _, bookmark := range bookmarksCollection.All() { | ||
names = append(names, bookmark.Name().ValuePretty()) | ||
} | ||
return names | ||
} | ||
return complete.PredictFunc(func(a complete.Args) []string { return thunk() }) | ||
} | ||
|
||
func CompletionPredictors(ctx app.Context) map[string]complete.Predictor { | ||
return map[string]complete.Predictor{ | ||
"file": complete.PredictFiles("*.klg"), | ||
"bookmark": predictBookmarks(ctx), | ||
"file_or_bookmark": complete.PredictOr(complete.PredictFiles("*.klg"), predictBookmarks(ctx)), | ||
} | ||
} |
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