-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (70 loc) · 1.72 KB
/
main.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
85
86
package main
import (
"os"
"path/filepath"
"time"
aw "github.com/deanishe/awgo"
"github.com/deanishe/awgo/update"
)
var (
// icons
updateAvailable = &aw.Icon{Value: "icons/update-available.png"}
maxCacheAge = 180 * time.Minute
repo = "mjhuber/alfred-repos"
query string
paths []string
// aw.Workflow is the main API
wf *aw.Workflow
)
// Options contains options for connecting to the gitlab API
type Options struct {
Directory string `env:"REPOS_DIRECTORY"`
}
func init() {
wf = aw.New(update.GitHub(repo), aw.HelpURL(repo+"/issues"))
paths = []string{}
}
func main() {
wf.Run(run)
}
// run executes the Script Filter.
func run() {
query := wf.Args()[0]
opts := &Options{}
cfg := aw.NewConfig()
if err := cfg.To(opts); err != nil {
wf.Fatalf("Error loading variables: %v", err)
return
}
err := filepath.Walk(opts.Directory, visit)
if err != nil {
wf.Fatalf("Error traversing path: %s", err.Error())
}
for _, path := range paths {
// Convenience method. Sets Item title to filename, subtitle
// to shortened path, arg to full path, and icon to file icon.
it := wf.NewFileItem(path)
// Alternate actions
it.NewModifier(aw.ModCmd).
Subtitle("Open in VSCode").
Var("action", "code")
it.NewModifier(aw.ModOpt).
Subtitle("Open in SublimeText").
Var("action", "sublime")
it.NewModifier(aw.ModCtrl).
Subtitle("Open in iTerm").
Var("action", "iterm")
}
if query != "" {
wf.Filter(query)
}
wf.WarnEmpty("No matching folders found", "Try a different query?")
wf.SendFeedback()
}
func visit(path string, f os.FileInfo, err error) error {
if f.IsDir() && f.Name() == ".git" {
parent := filepath.Dir(path)
paths = append(paths, parent)
}
return nil
}