-
Notifications
You must be signed in to change notification settings - Fork 1
/
block.go
87 lines (75 loc) · 1.54 KB
/
block.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
package main
import (
"flag"
"os"
"strings"
"time"
"github.com/kcmerrill/block/pkg/block"
homedir "github.com/mitchellh/go-homedir"
)
func main() {
debug := flag.Bool("debug", false, "Debug")
defaultCommand := flag.String("default-command", "open", "The default command to use. 'cd' would be another alternative.")
flag.Parse()
var query string
var action string
args := flag.Args()
switch len(args) {
case 0:
os.Exit(1)
case 1:
action = ""
query = args[0]
case 2:
action = args[0]
query = args[1]
}
ignoreIfContains := []string{
"/.git/",
"/vendor/",
"/node_modules/",
"/gems/",
"/go/pkg/", // hmmm ... just me?
"/cache/",
"/library/",
"downloads/", // could be iffy ...
"/album artwork/",
".app/",
"/.", // controversial. Don't @ me
}
ignoreIfStartsWith := []string{
"/network",
"/system",
"/volumes",
"/bin",
"/cores",
"/dev",
"/keybase",
"/net",
"/opt",
"/private",
"/usr",
"/var",
"/sbin",
"/applications/",
}
homeDir, _ := homedir.Dir()
boostDirs := map[string]int{
strings.ToLower(homeDir) + "/block/": 2,
}
overrideDirs := map[string]string{
strings.ToLower(homeDir) + "/block": "bash -c",
}
b := &block.Block{
IgnoreIfContains: ignoreIfContains,
IgnoreIfStartsWith: ignoreIfStartsWith,
Timeout: 1 * time.Second,
Query: strings.ToLower(query),
Action: action,
Debug: *debug,
Boosted: boostDirs,
Overrides: overrideDirs,
DefaultCommand: *defaultCommand,
}
block.New(b)
}