This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
urls.go
92 lines (77 loc) · 1.66 KB
/
urls.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
//
// Copyright (c) 2017 Dean Jackson <[email protected]>
//
// MIT Licence. See http://opensource.org/licenses/MIT
//
// Created on 2017-10-23
//
package main
import (
"net/url"
aw "github.com/deanishe/awgo"
)
// URLer is an item with a URL.
type URLer interface {
Title() string
Subtitle() string
URL() string
UID() string
Copytext() string
Largetype() string
Icon() *aw.Icon
}
// URLerItem returns a feedback Item for a URLer.
func URLerItem(u URLer) *aw.Item {
it := wf.NewItem(u.Title()).
Subtitle(u.Subtitle()).
UID(u.UID()).
Valid(true).
Copytext(u.Copytext()).
Largetype(u.Largetype()).
Icon(u.Icon()).
Var("ALSF_UID", u.UID()).
Var("ALSF_URL", u.URL()).
Var("ALSF_ACTION", urlActionDefault).
Var("action", "open")
URL, err := url.Parse(u.URL())
if err == nil {
if searchHostnames {
// Add hostname to search keys
it.Match(u.Title() + " " + URL.Hostname())
}
if URL.Scheme == "http" || URL.Scheme == "https" {
it.NewModifier("cmd").
Subtitle("Other actions…").
Var("action", "actions").
Icon(IconActions)
// Custom actions
var (
action URLActionable
actions = []struct {
action string
key aw.ModKey
}{
{urlActionFn, "fn"},
{urlActionCtrl, "ctrl"},
{urlActionOpt, "alt"},
{urlActionShift, "shift"},
}
)
for _, a := range actions {
if a.action == "" { // unset
continue
}
// Validate action
if action = URLAction(a.action); action == nil {
continue
}
it.NewModifier(a.key).
Subtitle(a.action).
Var("action", "url-action").
Var("ALSF_ACTION", a.action).
Icon(action.Icon())
}
}
}
return it
}