-
Notifications
You must be signed in to change notification settings - Fork 6
/
finder.go
84 lines (64 loc) · 1.43 KB
/
finder.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package modules
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/abenz1267/walker/config"
"github.com/boyter/gocodewalker"
)
type Finder struct {
prefix string
switcherExclusive bool
}
func (f Finder) Entries(ctx context.Context, term string) []Entry {
e := []Entry{}
if len(term) < 2 {
return e
}
homedir, err := os.UserHomeDir()
if err != nil {
log.Panic(err)
}
fileListQueue := make(chan *gocodewalker.File)
fileWalker := gocodewalker.NewFileWalker(homedir, fileListQueue)
errorHandler := func(e error) bool {
log.Println(e)
return true
}
fileWalker.SetErrorHandler(errorHandler)
go fileWalker.Start()
for f := range fileListQueue {
e = append(e, Entry{
Label: strings.TrimPrefix(strings.TrimPrefix(f.Location, homedir), "/"),
Sub: "fzf",
Exec: fmt.Sprintf("xdg-open %s", f.Location),
DragDrop: true,
DragDropData: f.Location,
Categories: []string{"finder", "fzf"},
Class: "finder",
Matching: Fuzzy,
})
}
return e
}
func (f Finder) Prefix() string {
return f.prefix
}
func (f Finder) Name() string {
return "finder"
}
func (f Finder) SwitcherExclusive() bool {
return f.switcherExclusive
}
func (Finder) Setup(cfg *config.Config) Workable {
f := &Finder{}
module := Find(cfg.Modules, f.Name())
if module == nil {
return nil
}
f.prefix = module.Prefix
f.switcherExclusive = module.SwitcherExclusive
return f
}