-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsearch-with-comments.go
57 lines (48 loc) · 1.25 KB
/
fsearch-with-comments.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
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/manifoldco/promptui"
)
func main() {
// Get the search term from the command line arguments
searchTerm := os.Args[1]
// Initialize a slice to store the matching files
var files []string
// Walk the file tree, starting from the current directory
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
// Skip directories
if info.IsDir() {
return nil
}
// If the file name contains the search term, add it to the list of files
if strings.Contains(path, searchTerm) {
files = append(files, path)
}
return nil
})
// If no files were found, print a message and return
if len(files) == 0 {
fmt.Println("No files found")
return
}
// Create a prompt to select a file from the list of matching files
prompt := promptui.Select{
Label: "Select file",
Items: files,
}
// Run the prompt and get the selected file
_, file, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
// Launch the selected file in the Goland editor, with the --new-instance option
err = exec.Command("open", "-a", "Goland", "--new-instance", file).Start()
if err != nil {
fmt.Printf("Failed to open file %v\n", err)
}
}