futil

package module
v0.0.0-...-2ab916d Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: BSD-3-Clause Imports: 12 Imported by: 1

README

futil

io/fs utils. This package provides a shell-like interface to search fs.FS.

example

This is an example of Shell function in example/dirfu.go

package main

import (
	"os"

	"github.com/rmatsuoka/futil"
)

func main() {
	if err := futil.Shell(os.DirFS("/"), os.Stdin, os.Stdout, os.Stderr, "zipfu % "); err != nil {
		os.Exit(1)
	}
}
$ go build
$ ./dirfu 
dirfu % ls -l
Lrwxrwxrwx           7 Mar  2  2020 bin
drwxr-xr-x        4096 Nov  5 11:56 boot
drwxrwxr-x        4096 Mar  2  2020 cdrom
drwxr-xr-x        5200 Nov 29 15:30 dev
...(omitted)
dirfu % glob usr/bin/*grep
usr/bin/egrep
usr/bin/fgrep
usr/bin/grep
usr/bin/pgrep
dirfu % read usr/bin/egrep
#!/bin/sh
exec grep -E "$@"
dirfu % exit
$  

available commands

get [-a] [-n] path [local_path]
	save a file in the local.

glob pattern
	search a filename with a pattern.

ls [-d] [-l] [path]
	like Unix ls command.

read path
	read a file.

walk [root]
	display all files from the root directory.

help
	list available commands.

exit
	exit the shell.

Documentation

Index

Constants

View Source
const (
	CommandList = `get [-a] [-n] path [local_path]
glob pattern
ls [-d] [-l] [path]
read path
walk [root]
help
exit`
)

Variables

View Source
var (
	// run exit command
	Exit = errors.New("exit")
)

Functions

func Eval

func Eval(fsys fs.FS, w io.Writer, ew io.Writer, args []string) error

func Fields

func Fields(b []byte) ([]string, error)

func LsLongFormats

func LsLongFormats(infos []fs.FileInfo) []string

func Shell

func Shell(fsys fs.FS, r io.Reader, w, ew io.Writer, prompt string) error

if failed to write error message to ew then panic

Types

This section is empty.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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