mfile

package
v0.0.0-...-94ee829 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(c *modulir.Context, source, target string) error

CopyFile is a shortcut for copy a file from a source path to a target path.

func CopyFileToDir

func CopyFileToDir(c *modulir.Context, source, targetDir string) error

CopyFileToDir is a shortcut for copy a file from a source path to a target directory.

func EnsureDir

func EnsureDir(c *modulir.Context, target string) error

EnsureDir ensures the existence of a target directory.

func EnsureSymlink(c *modulir.Context, source, target string) error

EnsureSymlink ensures the existence of a symbolic link that maps a target path to a source path.

func Exists

func Exists(file string) bool

Exists is a shortcut to check if a file exists. It panics if encountering an unexpected error.

func IsBackup

func IsBackup(base string) bool

IsBackup indicates whether a given filename is a backup file (i.e. prefixed by `~`).

func IsHidden

func IsHidden(base string) bool

IsHidden indicates whether a given filename is a hidden file (i.e. prefixed by `.`).

func IsMeta

func IsMeta(base string) bool

IsMeta indicates whether a given filename is a "meta" file (i.e. prefixed by `_`).

func MustAbs

func MustAbs(path string) string

MustAbs is a shortcut variant of filepath.Abs which panics instead of returning an error.

func ReadDir

func ReadDir(c *modulir.Context, source string) ([]string, error)

ReadDir reads files in a directory and returns a list of file paths.

Unlike os.ReadDir, this function skips hidden, "meta" (i.e. prefixed by an underscore), and Vim backup (i.e. suffixed with a tilde) files, and returns a list of full paths (easier to plumb into other functions), and sets up a watch on the listed source.

func ReadDirCached

func ReadDirCached(c *modulir.Context, source string,
	opts *ReadDirOptions,
) ([]string, error)

ReadDirCached is the same as ReadDirWithOptions, but it caches results for some amount of time to make it faster. The downside of this of course is that we occasionally get a stale cache when a new file is added and don't see it.

func ReadDirWithOptions

func ReadDirWithOptions(c *modulir.Context, source string,
	opts *ReadDirOptions,
) ([]string, error)

ReadDirWithOptions reads files in a directory and returns a list of file paths.

Unlike ReadDir, its behavior can be tweaked.

Types

type ReadDirOptions

type ReadDirOptions struct {
	// RecurseDir tells the function to recurse into subdirectories.
	RecurseDirs bool

	// ShowBackup tells the function to not skip backup files like those
	// produced by Vim. These are suffixed with a tilde '~'.
	ShowBackup bool

	// ShowDirs tell the function not to skip directories.
	ShowDirs bool

	// ShowHidden tells the function to not skip hidden files (prefixed with a
	// dot '.').
	ShowHidden bool

	// ShowMeta tells the function to not skip so-called "meta" files
	// (prefixed with an underscore '_').
	ShowMeta bool
}

ReadDirOptions are options for ReadDirWithOptions.

Jump to

Keyboard shortcuts

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