Skip to content

Commit

Permalink
Exclude certain file types from file picker
Browse files Browse the repository at this point in the history
  • Loading branch information
paololazzari committed Oct 22, 2023
1 parent 60f355d commit 44721f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"golang.org/x/term"
)

const version = "0.2.3"
const version = "0.2.4"

func completionCommand() *cobra.Command {
return &cobra.Command{
Expand Down
14 changes: 13 additions & 1 deletion src/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ func (ui *UI) changedText() func() {
}
}

// Helper function to exclude certain file types from file picker
func isExtensionInvalid(fileExtension string) bool {
invalidExtensions := [...]string{".gif", ".png"}
for _, invalidExtension := range invalidExtensions {
if invalidExtension == fileExtension {
return true
}
}
return false
}

// Helper function for populating nodes of TreeNode
func add(target *tview.TreeNode, path string, ui *UI) {
files, err := ioutil.ReadDir(path)
Expand All @@ -296,7 +307,8 @@ func add(target *tview.TreeNode, path string, ui *UI) {
scanner.Split(bufio.ScanLines)
scanner.Scan()
text := string(scanner.Text())
if utf8.ValidString(text) {
fileExtension := filepath.Ext(file.Name())
if utf8.ValidString(text) && !isExtensionInvalid(fileExtension) {
target.AddChild(node)
nodeRef := nodeReference{filepath.Join(path, file.Name()), text}
node.SetReference(nodeRef)
Expand Down

0 comments on commit 44721f7

Please sign in to comment.