MCPcopy Index your code
hub / github.com/Bios-Marcel/wastebasket

github.com/Bios-Marcel/wastebasket @v2.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.3 ↗ · + Follow
83 symbols 188 edges 22 files 24 documented · 29% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Wastebasket

Go Reference CI codecoverage

Wastebasket is a go library / CLI tool allowing you to interact with your system trashbin. It supports nix-systems (such as Linux and BSD) and Windows.

Documentation

Further documentation can be found at /docs.

Dependencies

Golang

For v2, go 1.23.4 or newer is required. For go 1.18 and up use the old implementation.

MacOS

Note that github.com/Bios-Marcel/wastebasket/v2 only supports MacOS patially. I simply can't be bothered maintaining it, as the performance is horrible and adding features is hard to test. Additionally, a "proper" implementation requires a very complex solution, that according to research won't work reliable. For now, we are stuck calling finder.

It's recommended to not call the Trash functon in a tight loop, put some time.Sleep calls, as the finder noise will sound very painful and cause your device to lag.

Restoring and querying files is not possible as of now.

IF you are willing to contribute and potentially maintain a proper MacOS implementation, I'd be glad to accept a PR.

Windows

There are no dependencies, it depends on the Shell32 API built into Windows.

No CGO required

Linux (Unix)

There are no dependencies, as Wastebasket offers a native golang implementation of the FreeDesktop Trash specification.

Additionally, the custom implementation should also work for systems such as BSD and its derivatives. However, this has not been tested and I do not plan on doing so, simply because GitHub does not currently support running tests on any BSD derivatives.

If anyone is willing to host a custom runner (which I think is possible), then I'd be open to this though.

No CGO required

Library usage

Grab it via

go get github.com/Bios-Marcel/wastebasket/v2

and you are ready to go.

Minimal Go example that creates a file, deletes it and empties the trashbin:

package main

import (
    "fmt"
    "os"

    "github.com/Bios-Marcel/wastebasket/v2"
)

func main() {
    os.WriteFile("test.txt", []byte("Test"), os.ModePerm)
    fmt.Println(wastebasket.Trash("test.txt"))
    wastebasket.Empty()
}

Make sure to check for ErrPlatformNotSupported if you are deploying to MacOS or nieche systems.

CLI usage

UNSTABLE, USE AT YOUR OWN RISK

Wastebasket can also be used as a commandline interface. You can build executables for each subcommand (such as empty) separately, or build wastebasket as a whole.

In order to do so, run

go build ./cmd/CMD

where CMD is whichever command you want to build.

Autocompletion

The CLI offers autocompletion for flags and pre-defined arguments.

Bash; Write the following into your bash profile:

source <(wastebasket completion bash)

Additionally, completion is supported for zsh, powershell and fish. For information, see Cobra shell completions

Tests

For windows, there is a utility that allows you to run linux or windows tests using containers. This prevents the utilitiy from accidentally deleting files or emptying your trashbin.

Simply execute:

test <linux|windows>

Note that this doesn't work when you are on linux.

Benchmarks

Run benchmarks using:

go test -bench=.

Extension points exported contracts — how you extend this code

TrashedFileInfo (Interface)
TrashedFileInfo represents a file that has been deleted and now resides in the trashbin. [2 implementers]
wastebasket.go

Core symbols most depended-on inside this repo

OriginalPath
called by 11
wastebasket.go
Restore
called by 6
wastebasket.go
Mounts
called by 4
internal/nix.go
DeletionDate
called by 3
wastebasket.go
getCache
called by 3
wastebasket_nix.go
queryTrashDir
called by 3
wastebasket_nix.go
RemoveAllIfExists
called by 3
internal/nix.go
createTrashedFile
called by 2
wastebasket_windows.go

Shape

Function 55
Method 19
Struct 8
Interface 1

Languages

Go100%

Modules by API surface

wastebasket_test.go10 symbols
wastebasket_nix_bench_test.go10 symbols
wastebasket_nix.go10 symbols
wastebasket_nix/nix.go9 symbols
wastebasket.go9 symbols
wastebasket_windows/windows.go8 symbols
wastebasket_windows.go8 symbols
internal/nix.go4 symbols
wastebasket_noop.go3 symbols
wastebasket_darwin.go3 symbols
wastebasket_nondarwin_test.go1 symbols
wastebasket_nix_test.go1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add wastebasket \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact