-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsRunner.go
45 lines (39 loc) · 951 Bytes
/
lsRunner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package fze
import (
"fmt"
"os/exec"
"regexp"
"strings"
)
func lsRunner(args []string, opts RunnerOptions) error {
isLong := false
if len(args) > 0 && args[0] == "-l" {
isLong = true
}
cmd := "ls " + fixArgs(args)
res, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return err
}
// Run the output from ls through fzf
outLines, err := runFzf(res, opts)
if err != nil {
return fmt.Errorf("runFzf: %v", err)
}
var paths []pathArg
for _, line := range outLines {
var path string
if isLong {
re := regexp.MustCompile(" +")
// ls -l output has a variable number of spaces between args. Clean this up by replacing multiple spaces with one space
path = re.ReplaceAllString(line, " ")
// take 9th column onwards as the path
path = strings.SplitN(path, " ", 9)[8]
} else {
path = line
}
paths = append(paths, pathArg{path: path})
}
// Run emacsclient
return openEditor(paths, opts)
}