Skip to content

Commit

Permalink
rename directory package
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 25, 2021
1 parent 144322a commit f006459
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion directory/directory.go → dirfs/dirfs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package directory
package dirfs

import (
"archive/zip"
Expand Down
6 changes: 3 additions & 3 deletions internal/statusbar/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
32 changes: 16 additions & 16 deletions internal/ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
}
Expand All @@ -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())
}

Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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())
}
Expand Down Expand Up @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
36 changes: 18 additions & 18 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -368,35 +368,35 @@ 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.
case "rm", "delete":
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:
Expand Down Expand Up @@ -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)
}

Expand All @@ -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.
Expand All @@ -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(),
Expand All @@ -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),
)
}

Expand All @@ -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),
)
}

Expand Down

0 comments on commit f006459

Please sign in to comment.