fileutil

package
v3.5.0-0.dev Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Overview

Package fileutil contains code to work with shell files, also known as shell scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasShebang

func HasShebang(bs []byte) bool

HasShebang reports whether bs begins with a valid sh or bash shebang. It supports variations with /usr and env.

Types

type ScriptConfidence

type ScriptConfidence int

ScriptConfidence defines how likely a file is to be a shell script, from complete certainty that it is not one to complete certainty that it is one.

const (
	// ConfNotScript describes files which are definitely not shell scripts,
	// such as non-regular files or files with a non-shell extension.
	ConfNotScript ScriptConfidence = iota

	// ConfIfShebang describes files which might be shell scripts, depending
	// on the shebang line in the file's contents. Since CouldBeScript only
	// works on os.FileInfo, the answer in this case can't be final.
	ConfIfShebang

	// ConfIsScript describes files which are definitely shell scripts,
	// which are regular files with a valid shell extension.
	ConfIsScript
)

func CouldBeScript deprecated

func CouldBeScript(info os.FileInfo) ScriptConfidence

CouldBeScript is a shortcut for CouldBeScript2(fs.FileInfoToDirEntry(info)).

Deprecated: prefer CouldBeScript2, which usually requires fewer syscalls.

func CouldBeScript2 added in v3.4.0

func CouldBeScript2(entry fs.DirEntry) ScriptConfidence

CouldBeScript2 reports how likely a directory entry is to be a shell script. It discards directories, symlinks, hidden files and files with non-shell extensions.

Jump to

Keyboard shortcuts

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