From ff01726cbc775d56c38798a938afa3fc03590736 Mon Sep 17 00:00:00 2001 From: Casual Date: Mon, 1 Jul 2024 13:59:05 +0300 Subject: [PATCH] add recursive support --- go.mod | 5 ++--- go.sum | 10 ++++------ tui.go | 3 +++ tui_viewport.go | 9 +++++---- watchFilesystem.go | 24 +++++++++++++++++++++++- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 5ea1322..83bb417 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,7 @@ require ( github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.26.1 github.com/charmbracelet/lipgloss v0.10.0 - github.com/fsnotify/fsnotify v1.7.0 - github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 + github.com/fsnotify/fsnotify v1.7.1-0.20240516151259-c1467c02fba5 github.com/projectdiscovery/goflags v0.1.50 ) @@ -42,7 +41,7 @@ require ( golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect + golang.org/x/sys v0.21.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.13.0 // indirect diff --git a/go.sum b/go.sum index 1c4afe8..e7899c8 100644 --- a/go.sum +++ b/go.sum @@ -18,12 +18,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fsnotify/fsnotify v1.7.1-0.20240516151259-c1467c02fba5 h1:6g0RCHJQ/7zcdimKwPNpjjepcKzT0O0sBnFMUXKLlfQ= +github.com/fsnotify/fsnotify v1.7.1-0.20240516151259-c1467c02fba5/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= -github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= -github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -83,8 +81,8 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/tui.go b/tui.go index 18cc252..5d41032 100644 --- a/tui.go +++ b/tui.go @@ -39,10 +39,13 @@ func initialModel() model { item("fmt code"), item("git add ."), // item("git commit"), TODO + // item("update go moduules"), TODO - go get -u item("git push"), // item("add to gitignore"), TODO // item("go mod init github_repo"), TODO // item("remove file from git history"), TODO + + } l := list.New(items, itemDelegate{}, defaultWidth, listHeight) // l.Title = "What do you want for dinner?" diff --git a/tui_viewport.go b/tui_viewport.go index 76355be..4f0632f 100644 --- a/tui_viewport.go +++ b/tui_viewport.go @@ -3,9 +3,9 @@ package main import ( // "fmt" - // "os" + "os" // "path/filepath" - "github.com/kardianos/osext" + // "github.com/kardianos/osext" // "unicode" "strings" @@ -46,8 +46,9 @@ func (m *model) footerView() string { return lipgloss.JoinHorizontal(lipgloss.Center, line) } -func getCurrentFolder() string { - folderPath, err := osext.ExecutableFolder() +func getCurrentFolder() string { //TODO bug, shows not current folder but folder of execuutable + // folderPath, err := osext.ExecutableFolder() + folderPath, err := os.Getwd() // folderPath, err := filepath.Abs(filepath.Dir(os.Args[0])) folders := strings.Split(folderPath, "/") if err != nil { diff --git a/watchFilesystem.go b/watchFilesystem.go index dc9d7f8..a94fcbc 100644 --- a/watchFilesystem.go +++ b/watchFilesystem.go @@ -5,6 +5,8 @@ package main import ( // "errors" // // "flag" + "io/fs" + "path/filepath" // "fmt" // "io/ioutil" // "log" @@ -28,7 +30,7 @@ import ( type fileUpdated bool // func watchFilesystem(tui *tea.Program) { -func watchFilesystem() { +func watchFilesystem() { //TODO watch subfolders // Create new watcher. watcher, err := fsnotify.NewWatcher() if err != nil { @@ -59,7 +61,27 @@ func watchFilesystem() { } }() + //get subdirectories + var subdirs []string + filepath.WalkDir(".", func(path string, file fs.DirEntry, err error) error { + if err != nil { + return err + } + if file.IsDir() { + // fmt.Println(path); + subdirs = append(subdirs,path) + } + + return nil; + }); + for _,dir := range subdirs { + err = watcher.Add(dir) + if err != nil { + errHandler(err, "Filesystem Watcher - Can't add current dir:") + } + } // Add a current path. + // err = watcher.Add("...") //TODO waiting for official recursive add https://github.com/fsnotify/fsnotify/issues/18 err = watcher.Add(".") if err != nil { errHandler(err, "Filesystem Watcher - Can't add current dir:")