fileutil

package
v3.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: BSD-3-Clause Imports: 4 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

Package fileutil allows inspecting shell files, such as detecting whether a file may be shell or extracting its shebang.

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 shell shebang. It supports variations with /usr and env.

func Shebang

func Shebang(bs []byte) string

Shebang parses a "#!" sequence from the beginning of the input bytes, and returns the shell that it points to.

For instance, it returns "sh" for "#!/bin/sh", and "bash" for "#!/usr/bin/env bash".

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 fs.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 fs.FileInfo) ScriptConfidence

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

Deprecated: prefer CouldBeScript2, which usually requires fewer syscalls.

func CouldBeScript2

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