Skip to content

Commit

Permalink
Adjust calling modes with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
gjhenrique committed Dec 12, 2022
1 parent c56cd7e commit bfecc3f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func runApps(cmd *cobra.Command, args []string) {
panic(err)
}

err = sh.SpawnAsyncProcess(entry.Exec)
err = sh.SpawnAsyncProcess(strings.Fields(entry.Exec), "")
if err != nil {
panic(err)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/search.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"os"
"fmt"
"strings"

"github.com/gjhenrique/lfzf/mode"
Expand Down Expand Up @@ -31,11 +31,10 @@ func search(cmd *cobra.Command, args []string) {

selectedMode := mode.FindModeByInput(modes, query)
entries, err := selectedMode.ListEntries()

s := sh.FormatEntries(entries)
os.Stdout.Write([]byte(s))

if err != nil {
panic(err)
}

s := sh.FormatEntries(entries)
fmt.Print(s)
}
7 changes: 1 addition & 6 deletions mode/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ func (m *Mode) ListEntries() ([]sh.Entry, error) {
func (m *Mode) Launch(input string) error {
cmd := strings.Fields(m.Exec)

input = strings.TrimPrefix(input, m.Prefix)
cmd = append(cmd, input)

err := sh.SpawnAsyncProcess(strings.Join(cmd, " "))
// TODO: Remove this back to async process
// _, err := sh.SpawnSyncProcess(cmd, nil)
err := sh.SpawnAsyncProcess(cmd, input)
if err != nil {
return err
}
Expand Down
16 changes: 9 additions & 7 deletions sh/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type Entry struct {
Text string
}

func SpawnAsyncProcess(command string) error {
execList := strings.Fields(command)
func SpawnAsyncProcess(command []string, args string) error {
args2 := append(command[1:], args)

cmd := exec.Command(execList[0], execList[1:]...)
cmd := exec.Command(command[0], args2...)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
Expand Down Expand Up @@ -82,19 +82,21 @@ func Fzf(entries []Entry) (*Entry, error) {
"--no-multi",
"--cycle",
"--no-info",
"--print-query",
"--bind",
bind,
}

fmt.Println(command)

result, err := SpawnSyncProcess(command, []byte(FormatEntries(entries)))
if err != nil {
return nil, err
}

// TODO: Make \034 a delimiter
separatedEntry := strings.Split(result, "\034")
splittedResult := strings.Split(result, "\n")
// query := splittedResult[0]

// TODO: Make \034 a variable
separatedEntry := strings.Split(splittedResult[1], "\034")
if len(separatedEntry) != 3 {
return nil, fmt.Errorf("Result %s not compatible with delimiters", result)
}
Expand Down

0 comments on commit bfecc3f

Please sign in to comment.