fileutil

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: BSD-3-Clause Imports: 4 Imported by: 2

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 added in v3.5.0

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 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