diff --git a/cmd/apps.go b/cmd/apps.go index e4d7c1c..934fa8f 100644 --- a/cmd/apps.go +++ b/cmd/apps.go @@ -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) } diff --git a/cmd/search.go b/cmd/search.go index 5069546..a262d42 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -1,7 +1,7 @@ package cmd import ( - "os" + "fmt" "strings" "github.com/gjhenrique/lfzf/mode" @@ -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) } diff --git a/mode/mode.go b/mode/mode.go index 1ec6d6f..aca2ab8 100644 --- a/mode/mode.go +++ b/mode/mode.go @@ -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 } diff --git a/sh/sh.go b/sh/sh.go index 2322b1c..5d60b6b 100644 --- a/sh/sh.go +++ b/sh/sh.go @@ -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, } @@ -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) }