filedrop

package
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Paths a terminal types at the start of the input when a user drags files onto it or pastes their paths, read as each terminal and shell writes them, and the files they name

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissing = errors.New("There is no file there.")
	ErrFolder  = errors.New("It is a folder, and only files are attached.")
	ErrSpecial = errors.New("It is not a regular file. It may be a device or a socket.")
	ErrDenied  = errors.New("You are not allowed to read it.")
)

Why a path a drop names gives no file to attach, each a sentence a user reads after the path

View Source
var ImageExtensions = map[string]bool{
	".png": true, ".jpg": true, ".jpeg": true, ".gif": true, ".webp": true,
	".bmp": true, ".tiff": true, ".tif": true, ".svg": true, ".ico": true,
}

Extensions of the files a drop takes for images

Functions

func Looks

func Looks(input string) bool

Whether the input starts as a terminal writes the path of a file dropped on it or pasted: the home folder, a folder relative to the one in use, a file:// address, a drive or a share of Windows, each perhaps quoted, PowerShell's call operator before a quote, and a root quoted or followed by more of a path, a slash or a dot, so a slash command such as /help is none

func Resolve

func Resolve(token, base string) (string, error)

The file a path names, read against base when it is relative, the working folder of the process when base is empty: a file:// address as its path (a share or a drive of Windows as Windows writes it), ~ and ~user as their home folders, a path of Windows off Windows as the path WSL mounts it at and an MSYS path such as /c/Users on Windows as its drive. The path as written first, then with its variables expanded. An error in words when it names no file there, a folder, no regular file or one that can't be read, with the whole path of what is there

func Split

func Split(input string) (string, string)

The first path of the input as one word of a shell, unquoted and unescaped, and the text after it. Quoted and bare parts that touch make one word, as a shell reads them: single quotes keep what is between them (for a quote mark of a name, a POSIX shell closes the quotes, escapes the mark and opens them again, and PowerShell doubles the mark), double quotes take a backslash before ", \, $ or a backtick as an escape, and outside quotes a backslash escapes the next character, as macOS Terminal, iTerm2, Ghostty and kitty write a dropped path. In a path of Windows, a backslash is a separator and a backtick, PowerShell's escape, escapes the next character. PowerShell's call operator before a quoted path is left out

Types

type Drop

type Drop struct {
	Files   []File
	Refused []Refusal
	Rest    string
}

What a drop at the start of the input names: the files, the paths refused, and the text after them, which is the message

func Detect

func Detect(input, base string) *Drop

The paths a terminal typed at the start of the input for files dropped on it or pasted, a relative one read against base, and the text after them, which is the message. nil when the input starts with no path that names something there. Several files dropped at once, each quoted or escaped as its terminal wrote it and set apart by spaces or lines, are each a file of the drop. A path that names a folder, no regular file or a file that can't be read is refused with why. A path with spaces typed bare is found too: the whole input, or its longest start up to a space that names a file

type File

type File struct {
	// Whole path, as written once read against the folder the input is relative to
	Path string
	// Its extension names an image
	Image bool
	Size  int64
}

A file a drop named

type Refusal

type Refusal struct {
	// Whole path of what is there, such as a folder. The path as written when it is not known
	Path string
	Err  error
}

A path a drop named that gives no file to attach, and why

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL