Skip to content

Commit

Permalink
update macos trash can support
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed Apr 17, 2024
1 parent 7d03edf commit bb55ece
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
21 changes: 16 additions & 5 deletions src/components/global_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package components

import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/Bios-Marcel/wastebasket"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

/* CURSOR CONTROLLER START */
Expand Down Expand Up @@ -346,11 +349,19 @@ func pasteItem(m model) model {
}
if m.copyItems.cut {
for _, item := range m.copyItems.items {

err := wastebasket.Trash(item)
if err != nil {
outPutLog("Paste item function move file to trash can error", err)
if runtime.GOOS == "darwin" {
cmd := exec.Command("osascript", "-e", fmt.Sprintf("tell application \"Finder\" to delete POSIX file \"%s\"", item))
err := cmd.Run()
if err != nil {
outPutLog("Paste item function move file to trash can error", err)
}
} else {
err := trash.Trash(item)
if err != nil {
outPutLog("Paste item function move file to trash can error", err)
}
}

}
if m.fileModel.filePanels[m.copyItems.originalPanel.index].location == m.copyItems.originalPanel.location {
m.fileModel.filePanels[m.copyItems.originalPanel.index].selected = panel.selected[:0]
Expand Down
19 changes: 14 additions & 5 deletions src/components/normal_controller.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package components

import (
"fmt"
"os"
"os/exec"
"path"
"runtime"
"time"

"github.com/Bios-Marcel/wastebasket"
"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/textinput"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

func enterPanel(m model) model {
Expand Down Expand Up @@ -164,10 +165,18 @@ func deleteSingleItem(m model) model {
messageId: id,
processNewState: newProcess,
}

err := wastebasket.Trash(panel.element[panel.cursor].location)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
var err error
if runtime.GOOS == "darwin" {
cmd := exec.Command("osascript", "-e", fmt.Sprintf("tell application \"Finder\" to delete POSIX file \"%s\"", panel.element[panel.cursor].location))
err = cmd.Run()
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
} else {
err = trash.Trash(panel.element[panel.cursor].location)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
}

if err != nil {
Expand Down
20 changes: 16 additions & 4 deletions src/components/select_controller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package components

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/Bios-Marcel/wastebasket"
"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/progress"
"github.com/lithammer/shortuuid"
"github.com/rkoesters/xdg/trash"
)

func singleItemSelect(m model) model {
Expand Down Expand Up @@ -186,9 +189,18 @@ func deleteMultipleItem(m model) model {
processNewState: p,
}
}
err := wastebasket.Trash(filePath)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
var err error
if runtime.GOOS == "darwin" {
cmd := exec.Command("osascript", "-e", fmt.Sprintf("tell application \"Finder\" to delete POSIX file \"%s\"", filePath))
err = cmd.Run()
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
} else {
err = trash.Trash(filePath)
if err != nil {
outPutLog("Delete single item function move file to trash can error", err)
}
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/components/string_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func prettierName(name string, width int, isDir bool, isSelected bool, bgColor l
if isSelected {
return stringColorRender(lipgloss.Color(style.color), bgColor).
Background(bgColor).
Render(style.icon + "") +
Render(style.icon + " ") +
filePanelItemSelectedStyle.
Render(truncateText(name, width))
} else {
Expand Down
1 change: 0 additions & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/MHNightCat/superfile
go 1.21.8

require (
github.com/Bios-Marcel/wastebasket v0.0.3
github.com/atotto/clipboard v0.1.4
github.com/barasher/go-exiftool v1.10.0
github.com/charmbracelet/bubbles v0.18.0
Expand Down
2 changes: 0 additions & 2 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/Bios-Marcel/wastebasket v0.0.3 h1:gyuMcoDav6n+sdynn9TDl1NN7GOAnoy227JErVSW3RM=
github.com/Bios-Marcel/wastebasket v0.0.3/go.mod h1:FChzXi1izqzdPb6BiNZmcZLGyTYiT61iGx9Rxx9GNeI=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down

0 comments on commit bb55ece

Please sign in to comment.