Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: Add partial match for use command #40

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions internal/actions/use.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package actions

import (
"sort"
"strings"

"github.com/TimothyYe/skm/internal/utils"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"gopkg.in/urfave/cli.v1"
"sort"
)

func Use(c *cli.Context) error {
Expand Down Expand Up @@ -46,11 +48,25 @@ func Use(c *cli.Context) error {
alias = result
}

// complete match key
_, ok := keyMap[alias]

if !ok {
color.Red("Key alias: %s doesn't exist!", alias)
return nil
// partial match key
canPartialMatch := false

for k, _ := range keyMap {
if strings.Index(k, alias) >= 0 {
alias = k
canPartialMatch = true
break
}
}

if !canPartialMatch {
color.Red("Key alias: %s doesn't exist!", alias)
return nil
}
}

// Set key with related alias as default used key
Expand Down