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

feat: pre-select stuff with fzf #324

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions cmd/kubectx/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,21 @@ func parseArgs(argv []string) Op {
if v == "--unset" || v == "-u" {
return UnsetOp{}
}

if v == "-" {
return SwitchOp{Target: "-"}
}
if new, old, ok := parseRenameSyntax(v); ok {
return RenameOp{New: new, Old: old}
}

if strings.HasPrefix(v, "-") && v != "-" {
if strings.HasPrefix(v, "-") {
return UnsupportedOp{Err: fmt.Errorf("unsupported option '%s'", v)}
}
if cmdutil.IsInteractiveMode(os.Stdout) {
return InteractiveSwitchOp{
SelfCmd: os.Args[0],
Query: argv[0],
}
}
return SwitchOp{Target: argv[0]}
}
return UnsupportedOp{Err: fmt.Errorf("too many arguments")}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kubectx/fzf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

type InteractiveSwitchOp struct {
SelfCmd string
Query string
}

type InteractiveDeleteOp struct {
Expand All @@ -50,7 +51,7 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
}
kc.Close()

cmd := exec.Command("fzf", "--ansi", "--no-preview")
cmd := exec.Command("fzf", "--ansi", "--no-preview", "--query", op.Query, "--select-1")
var out bytes.Buffer
cmd.Stdin = os.Stdin
cmd.Stderr = stderr
Expand Down
11 changes: 10 additions & 1 deletion cmd/kubens/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ func parseArgs(argv []string) Op {
if v == "--current" || v == "-c" {
return CurrentOp{}
}
if strings.HasPrefix(v, "-") && v != "-" {
if v == "-" {
return SwitchOp{Target: "-"}
}
if strings.HasPrefix(v, "-") {
return UnsupportedOp{Err: fmt.Errorf("unsupported option '%s'", v)}
}
if cmdutil.IsInteractiveMode(os.Stdout) {
return InteractiveSwitchOp{
SelfCmd: os.Args[0],
Query: argv[0],
}
}
return SwitchOp{Target: argv[0]}
}
return UnsupportedOp{Err: fmt.Errorf("too many arguments")}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kubens/fzf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

type InteractiveSwitchOp struct {
SelfCmd string
Query string
}

// TODO(ahmetb) This method is heavily repetitive vs kubectx/fzf.go.
Expand All @@ -47,7 +48,7 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
}
defer kc.Close()

cmd := exec.Command("fzf", "--ansi", "--no-preview")
cmd := exec.Command("fzf", "--ansi", "--no-preview", "--query", op.Query, "--select-1")
var out bytes.Buffer
cmd.Stdin = os.Stdin
cmd.Stderr = stderr
Expand Down