-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (77 loc) · 1.54 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
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"path/filepath"
"github.com/ktr0731/go-fuzzyfinder"
)
type Repo struct {
name string
path string
readme string
}
func tp() {
fmt.Println(len(ghqList()))
for _, name := range ghqList() {
fmt.Println(name)
}
}
func main() {
realPaths := func() []string {
var list []string
for _, repoName := range ghqList() {
list = append(list, repoName)
}
return list
}
repos := packing(realPaths())
idx, err := fuzzyfinder.Find(
repos,
func(i int) string {
return repos[i].name
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
return ""
}
return fmt.Sprintf("Name: %s\n\n%s",
repos[i].name, repos[i].readme)
}))
if err != nil {
}
fullPath := filepath.Join(ghqRoot(), repos[idx].path)
if filepath.Base(fullPath) == "sandbox" {
list := packing(sandboxList(fullPath))
if filepath.Base(fullPath) == "sandbox" {
idx, err := fuzzyfinder.Find(
list,
func(i int) string {
return list[i].name
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
return ""
}
return fmt.Sprintf("Name: %s\n\n%s",
list[i].name, list[i].readme)
}))
if err != nil {
}
fmt.Println(list[idx].path)
}
} else {
fmt.Println(fullPath)
}
}
func packing(repoPaths []string) []Repo {
var repos []Repo
for _, path := range repoPaths {
readme := READMEContent(path)
repo := Repo{
name: filepath.Base(path),
path: path,
readme: readme,
}
repos = append(repos, repo)
}
return repos
}