-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsearch.go
More file actions
45 lines (39 loc) · 749 Bytes
/
fsearch.go
File metadata and controls
45 lines (39 loc) · 749 Bytes
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
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/manifoldco/promptui"
)
func main() {
searchTerm := os.Args[1]
var files []string
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if strings.Contains(path, searchTerm) {
files = append(files, path)
}
return nil
})
if len(files) == 0 {
fmt.Println("No files found")
return
}
prompt := promptui.Select{
Label: "Select file",
Items: files,
}
_, file, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
err = exec.Command("goland", "--new-instance", file).Start()
if err != nil {
fmt.Printf("Failed to open file %v\n", err)
}
}