diff --git a/directory/directory.go b/dirfs/dirfs.go similarity index 99% rename from directory/directory.go rename to dirfs/dirfs.go index 270e679..fa61aff 100644 --- a/directory/directory.go +++ b/dirfs/dirfs.go @@ -1,4 +1,4 @@ -package directory +package dirfs import ( "archive/zip" diff --git a/internal/statusbar/statusbar.go b/internal/statusbar/statusbar.go index fcd6de7..0d2db0d 100644 --- a/internal/statusbar/statusbar.go +++ b/internal/statusbar/statusbar.go @@ -5,7 +5,7 @@ import ( "io/fs" "strings" - "github.com/knipferrc/fm/directory" + "github.com/knipferrc/fm/dirfs" "github.com/knipferrc/fm/icons" "github.com/charmbracelet/bubbles/spinner" @@ -176,9 +176,9 @@ func (m Model) View() string { selectedFile = m.SelectedFile.Name() fileCount = fmt.Sprintf("%d/%d", m.Cursor+1, m.TotalFiles) - currentPath, err := directory.GetWorkingDirectory() + currentPath, err := dirfs.GetWorkingDirectory() if err != nil { - currentPath = directory.CurrentDirectory + currentPath = dirfs.CurrentDirectory } fileInfo, err := m.SelectedFile.Info() diff --git a/internal/ui/commands.go b/internal/ui/commands.go index 98f2e0d..c79ee90 100644 --- a/internal/ui/commands.go +++ b/internal/ui/commands.go @@ -14,7 +14,7 @@ import ( // "image/png" is needed for the image.Decode function. _ "image/png" - "github.com/knipferrc/fm/directory" + "github.com/knipferrc/fm/dirfs" "github.com/knipferrc/fm/internal/colorimage" "github.com/knipferrc/fm/internal/markdown" "github.com/knipferrc/fm/internal/sourcecode" @@ -39,7 +39,7 @@ type readFileContentMsg struct { // updateDirectoryListing updates the directory listing based on the name of the direcoctory provided. func (m Model) updateDirectoryListing(name string) tea.Cmd { return func() tea.Msg { - files, err := directory.GetDirectoryListing(name, m.dirTree.ShowHidden) + files, err := dirfs.GetDirectoryListing(name, m.dirTree.ShowHidden) if err != nil { return errorMsg(err.Error()) } @@ -51,7 +51,7 @@ func (m Model) updateDirectoryListing(name string) tea.Cmd { // renameFileOrDir renames a file or directory based on the name and value provided. func (m Model) renameFileOrDir(name, value string) tea.Cmd { return func() tea.Msg { - if err := directory.RenameDirOrFile(name, value); err != nil { + if err := dirfs.RenameDirOrFile(name, value); err != nil { return errorMsg(err.Error()) } @@ -62,7 +62,7 @@ func (m Model) renameFileOrDir(name, value string) tea.Cmd { // moveDirectoryItem moves a file to the current working directory. func (m Model) moveDirectoryItem(name string) tea.Cmd { return func() tea.Msg { - workingDir, err := directory.GetWorkingDirectory() + workingDir, err := dirfs.GetWorkingDirectory() if err != nil { return errorMsg(err.Error()) } @@ -75,11 +75,11 @@ func (m Model) moveDirectoryItem(name string) tea.Cmd { // the same file name that it had. dst := fmt.Sprintf("%s/%s", workingDir, name) - if err = directory.MoveDirectoryItem(src, dst); err != nil { + if err = dirfs.MoveDirectoryItem(src, dst); err != nil { return errorMsg(err.Error()) } - files, err := directory.GetDirectoryListing(m.initialMoveDirectory, m.dirTree.ShowHidden) + files, err := dirfs.GetDirectoryListing(m.initialMoveDirectory, m.dirTree.ShowHidden) if err != nil { return errorMsg(err.Error()) } @@ -91,7 +91,7 @@ func (m Model) moveDirectoryItem(name string) tea.Cmd { // deleteDir deletes a directory based on the name provided. func (m Model) deleteDir(name string) tea.Cmd { return func() tea.Msg { - if err := directory.DeleteDirectory(name); err != nil { + if err := dirfs.DeleteDirectory(name); err != nil { return errorMsg(err.Error()) } @@ -102,7 +102,7 @@ func (m Model) deleteDir(name string) tea.Cmd { // deleteFile deletes a file based on the name provided. func (m Model) deleteFile(name string) tea.Cmd { return func() tea.Msg { - if err := directory.DeleteFile(name); err != nil { + if err := dirfs.DeleteFile(name); err != nil { return errorMsg(err.Error()) } @@ -113,7 +113,7 @@ func (m Model) deleteFile(name string) tea.Cmd { // readFileContent reads the content of a file and returns it. func (m Model) readFileContent(file fs.DirEntry, width, height int) tea.Cmd { return func() tea.Msg { - content, err := directory.ReadFileContent(file.Name()) + content, err := dirfs.ReadFileContent(file.Name()) if err != nil { return errorMsg(err.Error()) } @@ -187,7 +187,7 @@ func (m Model) redrawImage(width, height int) tea.Cmd { // createDir creates a directory based on the name provided. func (m Model) createDir(name string) tea.Cmd { return func() tea.Msg { - if err := directory.CreateDirectory(name); err != nil { + if err := dirfs.CreateDirectory(name); err != nil { return errorMsg(err.Error()) } @@ -198,7 +198,7 @@ func (m Model) createDir(name string) tea.Cmd { // createFile creates a file based on the name provided. func (m Model) createFile(name string) tea.Cmd { return func() tea.Msg { - if err := directory.CreateFile(name); err != nil { + if err := dirfs.CreateFile(name); err != nil { return errorMsg(err.Error()) } @@ -209,7 +209,7 @@ func (m Model) createFile(name string) tea.Cmd { // zipDirectory zips a directory based on the name provided. func (m Model) zipDirectory(name string) tea.Cmd { return func() tea.Msg { - if err := directory.Zip(name); err != nil { + if err := dirfs.Zip(name); err != nil { return errorMsg(err.Error()) } @@ -220,7 +220,7 @@ func (m Model) zipDirectory(name string) tea.Cmd { // unzipDirectory unzips a directory based on the name provided. func (m Model) unzipDirectory(name string) tea.Cmd { return func() tea.Msg { - if err := directory.Unzip(name); err != nil { + if err := dirfs.Unzip(name); err != nil { return errorMsg(err.Error()) } @@ -231,7 +231,7 @@ func (m Model) unzipDirectory(name string) tea.Cmd { // copyFile copies a file based on the name provided. func (m Model) copyFile(name string) tea.Cmd { return func() tea.Msg { - if err := directory.CopyFile(name); err != nil { + if err := dirfs.CopyFile(name); err != nil { return errorMsg(err.Error()) } @@ -242,7 +242,7 @@ func (m Model) copyFile(name string) tea.Cmd { // copyDirectory copies a directory based on the name provided. func (m Model) copyDirectory(name string) tea.Cmd { return func() tea.Msg { - if err := directory.CopyDirectory(name); err != nil { + if err := dirfs.CopyDirectory(name); err != nil { return errorMsg(err.Error()) } @@ -263,7 +263,7 @@ func (m Model) getDirectoryItemSize(name string) tea.Cmd { defer cancel() <-ctx.Done() if ctx.Err() == context.DeadlineExceeded { - size, err := directory.GetDirectoryItemSize(name) + size, err := dirfs.GetDirectoryItemSize(name) if err != nil { return directoryItemSizeMsg("N/A") } diff --git a/internal/ui/init.go b/internal/ui/init.go index 1e32c23..f03083a 100644 --- a/internal/ui/init.go +++ b/internal/ui/init.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/knipferrc/fm/directory" + "github.com/knipferrc/fm/dirfs" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" @@ -41,8 +41,8 @@ func (m Model) Init() tea.Cmd { cmds = append(cmds, m.updateDirectoryListing(filePath)) } - case m.appConfig.Settings.StartDir == directory.HomeDirectory: - homeDir, err := directory.GetHomeDirectory() + case m.appConfig.Settings.StartDir == dirfs.HomeDirectory: + homeDir, err := dirfs.GetHomeDirectory() if err != nil { log.Fatal(err) } diff --git a/internal/ui/update.go b/internal/ui/update.go index 85a32b8..115e842 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -3,7 +3,7 @@ package ui import ( "fmt" - "github.com/knipferrc/fm/directory" + "github.com/knipferrc/fm/dirfs" "github.com/knipferrc/fm/internal/statusbar" "github.com/charmbracelet/bubbles/key" @@ -273,10 +273,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keys.Left): if !m.showCommandBar && m.primaryPane.GetIsActive() { m.statusBar.SetItemSize("") - m.previousDirectory, _ = directory.GetWorkingDirectory() + m.previousDirectory, _ = dirfs.GetWorkingDirectory() return m, m.updateDirectoryListing( - fmt.Sprintf("%s/%s", m.previousDirectory, directory.PreviousDirectory), + fmt.Sprintf("%s/%s", m.previousDirectory, dirfs.PreviousDirectory), ) } @@ -315,7 +315,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if !m.showCommandBar && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 { if m.dirTree.GetSelectedFile().IsDir() && !m.statusBar.CommandBarFocused() { m.statusBar.SetItemSize("") - currentDir, _ := directory.GetWorkingDirectory() + currentDir, _ := dirfs.GetWorkingDirectory() return m, m.updateDirectoryListing( fmt.Sprintf("%s/%s", currentDir, m.dirTree.GetSelectedFile().Name()), @@ -368,21 +368,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "mkdir": return m, tea.Sequentially( m.createDir(value), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) // Create a new file based on the value passed. case "touch": return m, tea.Sequentially( m.createFile(value), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) // Rename the currently selected file or folder based on the value passed. case "mv", "rename": return m, tea.Sequentially( m.renameFileOrDir(m.dirTree.GetSelectedFile().Name(), value), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) // Delete the currently selected item. @@ -390,13 +390,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.dirTree.GetSelectedFile().IsDir() { return m, tea.Sequentially( m.deleteDir(m.dirTree.GetSelectedFile().Name()), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) } return m, tea.Sequentially( m.deleteFile(m.dirTree.GetSelectedFile().Name()), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) default: @@ -424,7 +424,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // command bar is not curently open. case key.Matches(msg, m.keys.OpenHomeDirectory): if !m.showCommandBar { - homeDir, _ := directory.GetHomeDirectory() + homeDir, _ := dirfs.GetHomeDirectory() return m, m.updateDirectoryListing(homeDir) } @@ -438,7 +438,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keys.ToggleHidden): if !m.showCommandBar && m.primaryPane.GetIsActive() { m.dirTree.ToggleHidden() - return m, m.updateDirectoryListing(directory.CurrentDirectory) + return m, m.updateDirectoryListing(dirfs.CurrentDirectory) } // Toggle between the two panes if the command bar is not currently active. @@ -453,7 +453,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if !m.showCommandBar && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 { m.inMoveMode = true m.primaryPane.ShowAlternateBorder(true) - m.initialMoveDirectory, _ = directory.GetWorkingDirectory() + m.initialMoveDirectory, _ = dirfs.GetWorkingDirectory() m.itemToMove = m.dirTree.GetSelectedFile() m.statusBar.SetContent( m.dirTree.GetTotalFiles(), @@ -468,22 +468,22 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Zip up the currently selected item. case key.Matches(msg, m.keys.Zip): if !m.showCommandBar && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 { - currentDir, _ := directory.GetWorkingDirectory() + currentDir, _ := dirfs.GetWorkingDirectory() return m, tea.Sequentially( m.zipDirectory(fmt.Sprintf("%s/%s", currentDir, m.dirTree.GetSelectedFile().Name())), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) } // Unzip the currently selected zip file. case key.Matches(msg, m.keys.Unzip): if !m.showCommandBar && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 { - currentDir, _ := directory.GetWorkingDirectory() + currentDir, _ := dirfs.GetWorkingDirectory() return m, tea.Sequentially( m.unzipDirectory(fmt.Sprintf("%s/%s", currentDir, m.dirTree.GetSelectedFile().Name())), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) } @@ -493,13 +493,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.dirTree.GetSelectedFile().IsDir() { return m, tea.Sequentially( m.copyDirectory(m.dirTree.GetSelectedFile().Name()), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) } return m, tea.Sequentially( m.copyFile(m.dirTree.GetSelectedFile().Name()), - m.updateDirectoryListing(directory.CurrentDirectory), + m.updateDirectoryListing(dirfs.CurrentDirectory), ) }