-
Notifications
You must be signed in to change notification settings - Fork 1
/
alfred.go
96 lines (80 loc) · 1.99 KB
/
alfred.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
87
88
89
90
91
92
93
94
95
96
package main
// Package is called aw
import (
"fmt"
"os"
"os/exec"
"strings"
aw "github.com/deanishe/awgo"
)
// Workflow is the main API
var (
alfredQuery string
_ = os.Setenv("alfred_workflow_bundleid", "1")
_ = os.Setenv("alfred_workflow_cache", "1")
_ = os.Setenv("alfred_workflow_data", "1")
wf *aw.Workflow
maxResults = 100
iconSet map[string]string
)
// Your workflow starts here
func run() {
libsummary := librarySummary()
iconSet = loadIcons()
args := wf.Args()
argSet := strings.Join(args[1:], "")
// Run sync operation in the background
if wf.IsRunning("sync") == false {
wf.RunInBackground("sync", exec.Command("gg", "sync"))
}
if len(args) > 0 {
alfredQuery = strings.Join(args[1:], "")
}
if len(argSet) == 0 {
wf.NewItem("New").
Icon(newIcon).
Arg("https://gist.github.com/").
Subtitle("Create a new gist").
Var("action", "new").
Valid(true)
wf.NewItem("Tags").
Icon(tagIcon).
Autocomplete("#").
Subtitle(fmt.Sprintf("%v Tags", libsummary.tags))
wf.NewItem("Language").
Icon(languageIcon).
Autocomplete("~").
Subtitle(fmt.Sprintf("%v Languages", libsummary.languages))
wf.NewItem("Starred").
Icon(starIcon).
Autocomplete("⭐").
Subtitle(fmt.Sprintf("%v Starred", libsummary.starred))
wf.NewItem("owner").
Icon(randomOwnerIcon()).
Autocomplete(":").
Subtitle(fmt.Sprintf("%v Owners", libsummary.owners))
wf.NewItem("sync")
wf.NewItem("set-editor")
wf.NewItem("login")
} else {
switch {
case strings.HasPrefix(alfredQuery, "#"):
fieldSummary("Tags")
case strings.HasPrefix(alfredQuery, "~"):
fieldSummary("Language")
case strings.HasPrefix(alfredQuery, ":"):
fieldSummary("Owner")
default:
queryGistsAlfred(alfredQuery)
}
//wf.NewItem(argSet)
}
// Send results to Alfred
wf.SendFeedback()
}
func runAlfred() {
wf = aw.New(aw.HelpURL("http://www.github.com/danielecook/gg"),
aw.MaxResults(maxResults))
outputFormat = "alfred"
wf.Run(run)
}