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
/
history.go
67 lines (53 loc) · 1.39 KB
/
history.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
//
// Copyright (c) 2017 Dean Jackson <[email protected]>
//
// MIT Licence. See http://opensource.org/licenses/MIT
//
// Created on 2017-10-22
//
package main
import (
"log"
"github.com/deanishe/awgo"
"github.com/deanishe/go-safari/history"
)
// doFilterHistory searches Safari history.
func doFilterHistory() error {
showUpdateStatus()
history.MaxSearchResults = maxResults * 10 // allow for lots of duplicates
wf.Configure(aw.MaxResults(maxResults))
entries, err := history.Search(query)
if err != nil {
return err
}
// Remove duplicates
var (
seen = map[string]bool{}
unique = []*history.Entry{}
)
for _, e := range entries {
if seen[e.URL] {
continue
}
seen[e.URL] = true
unique = append(unique, e)
}
entries = unique
log.Printf("%d results for \"%s\"", len(entries), query)
for _, e := range entries {
URLerItem(&hURLer{e})
}
wf.WarnEmpty("No matching entries found", "Try a different query?")
wf.SendFeedback()
return nil
}
type hURLer struct {
e *history.Entry
}
func (u *hURLer) Title() string { return u.e.Title }
func (u *hURLer) Subtitle() string { return u.e.URL }
func (u *hURLer) URL() string { return u.e.URL }
func (u *hURLer) UID() string { return u.e.URL }
func (u *hURLer) Copytext() string { return u.e.URL }
func (u *hURLer) Largetype() string { return u.e.URL }
func (u *hURLer) Icon() *aw.Icon { return IconHistory }