Documentation
¶
Index ¶
- Variables
- func Bash(bashCommand string) (string, error)
- func BinDirectory(filename string) bool
- func CanRead(filename string) bool
- func ClearCache()
- func DataReadyOnStdin() bool
- func DirectoryWithFiles(path string) (bool, error)
- func Exists(path string) bool
- func ExistsCached(path string) bool
- func FileHas(path, what string) bool
- func FilterOutBinaryFiles(filenames []string) []string
- func FilterOutBinaryFilesAccurate(filenames []string) []string
- func FindFile(substring string) ([]string, error)
- func Fish(fishCommand string) (string, error)
- func GetPID(name string) (int64, error)
- func GetProcPath(pid int, suffix string) (string, error)
- func HasProcess(name string) bool
- func HeaderSearch(absCppFilename string, headerExtensions []string, maxTime time.Duration) (string, error)
- func IsBinary(filename string) bool
- func IsBinaryAccurate(filename string) bool
- func IsDir(path string) bool
- func IsDirAndNotSymlink(path string) bool
- func IsEmpty(path string) bool
- func IsExecutable(path string) bool
- func IsExecutableCached(path string) bool
- func IsFile(path string) bool
- func IsFileOrSymlink(path string) bool
- func IsRealPath(path string) bool
- func IsRelative(path string) string
- func IsSymlink(path string) bool
- func PathHas(executable string) bool
- func PathHasCached(executable string) bool
- func Pkill(name string) (int, error)
- func ReadString(filename string) string
- func RemoveFile(path string) error
- func Run(commandString string) error
- func Shell(shellCommand string) (string, error)
- func ShortPath(path string) string
- func TimestampedFilename(filename string) string
- func Touch(filename string) error
- func Which(executable string) string
- func WhichCached(executable string) string
Constants ¶
This section is empty.
Variables ¶
var Binary = IsBinary
var BinaryAccurate = IsBinaryAccurate
var Dir = IsDir
var DirAndNotSymlink = IsDirAndNotSymlink
var Empty = IsEmpty
Empty checks if the given path is an empty file. Also returns false if something went wrong.
var Executable = IsExecutable
var ExecutableCached = IsExecutableCached
ExecutableCached checks if the given path exists and is an executable file, with cache support. Assumes that the filesystem permissions have not changed since the last check.
var File = IsFile
var FileOrSymlink = IsFileOrSymlink
var RealPath = IsRealPath
RealPath checks if the given path is the same if symlinks are not followed (like "pwd -P" / the "real" path) Also returns false if something went wrong.
var Relative = IsRelative
var Symlink = IsSymlink
Functions ¶
func Bash ¶ added in v1.9.3
Bash runs the given command with /bin/bash, or "bash" in the $PATH, and returns the combined output.
func BinDirectory ¶
BinDirectory will check if the given filename is in one of these directories: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, ~/.bin, ~/bin, ~/.local/bin
func CanRead ¶ added in v1.1.0
CanRead checks if 1 byte can actually be read from the given filename
func DataReadyOnStdin ¶
func DataReadyOnStdin() bool
DataReadyOnStdin checks if data is ready on stdin
func DirectoryWithFiles ¶ added in v1.8.0
DirectoryWithFiles checks if the given path is a directory and contains at least one file
func ExistsCached ¶ added in v1.5.0
ExistsCached checks if the given path exists, using a cache for faster access. Assumes that the filesystem has not changed since the last check.
func FilterOutBinaryFiles ¶
FilterOutBinaryFiles filters out files that are either binary or can not be read
func FilterOutBinaryFilesAccurate ¶ added in v1.10.5
FilterOutBinaryFilesAccurate filters out files that are either binary or can not be read
func FindFile ¶ added in v1.10.1
FindFile searches for files that contain the given substring in their filename starting from the current directory. It returns all matches as absolute paths or an error if the search fails.
func Fish ¶ added in v1.9.3
Fish runs the given command with /usr/bin/fish, or "fish" in the $PATH, and returns the combined output.
func GetProcPath ¶ added in v1.10.3
GetProcPath resolves and returns the specified path (e.g., "exe", "cwd") for the process identified by pid. It returns an error if the path cannot be resolved.
func HasProcess ¶ added in v1.10.3
HasProcess returns true if a valid PID for the given process name is found in /proc, similar to how pgrep works
func HeaderSearch ¶ added in v1.10.1
func HeaderSearch(absCppFilename string, headerExtensions []string, maxTime time.Duration) (string, error)
HeaderSearch will search for a corresponding file, given a slice of extensions. This is useful for ie. finding a corresponding .h file for a .c file. The search starts in the current directory, then searches every parent directory in depth. TODO: Search sibling and parent directories named "include" first, then search the rest.
func IsBinary ¶ added in v1.4.0
IsBinary returns true if the given filename can be read and is a binary file. It checks if the given filename is a regular file first, to avoid hangs when reading named pipes.
func IsBinaryAccurate ¶ added in v1.10.5
IsBinaryAccurate returns true if the given filename can be read and is a binary file. It checks if the given filename is a regular file first, to avoid hangs when reading named pipes.
func IsDirAndNotSymlink ¶ added in v1.10.8
IsDirAndNotSymlink checks if the given path exists and is a directory that is not a symlink
func IsEmpty ¶ added in v1.10.0
IsEmpty checks if the given path is an empty file. Also returns false if something went wrong.
func IsExecutable ¶ added in v1.9.0
IsExecutable checks if the given path exists and is executable
func IsExecutableCached ¶ added in v1.9.0
IsExecutableCached checks if the given path exists and is an executable file, with cache support. Assumes that the filesystem permissions have not changed since the last check.
func IsFileOrSymlink ¶
IsFileOrSymlink checks if the given path exists and is a regular file or a symbolic link
func IsRealPath ¶ added in v1.10.2
IsRealPath checks if the given path is the same if symlinks are not followed (like "pwd -P" / the "real" path) Also returns false if something went wrong.
func IsRelative ¶ added in v1.10.0
IsRelative takes an absolute or relative path and attempts to return it relative to the current directory. If there are errors, it simply returns the given path.
func PathHasCached ¶ added in v1.7.0
PathHasCached checks if the given executable is in $PATH (looks in the cache first and then caches the result)
func Pkill ¶ added in v1.10.3
Pkill tries to find and kill all processes that match the given name. Returns the number of processes killed, and an error, if anything went wrong.
func ReadString ¶ added in v1.1.0
ReadString returns the contents of the given filename as a string. Returns an empty string if there were errors.
func RemoveFile ¶ added in v1.5.0
RemoveFile deletes a file, but it only returns an error if the file both exists and also could not be removed
func Run ¶ added in v1.9.2
Run tries to run the given command, without using a shell. No output is returned, only an error, if something went wrong.
func Shell ¶ added in v1.9.3
Shell runs the given command with /bin/sh and returns the combined output
func ShortPath ¶
ShortPath replaces the home directory with ~ in a given path. The given path is expected to contain the home directory path either 0 or 1 times, and if it contains the path to the home directory, it is expected to be at the start of the given string.
func TimestampedFilename ¶
TimestampedFilename prefixes the given filename with a timestamp
func Touch ¶ added in v1.5.0
Touch behaves like "touch" on the command line, and creates a file or updates the timestamp
func Which ¶
Which tries to find the given executable name in the $PATH Returns an empty string if not found.
func WhichCached ¶ added in v1.6.0
WhichCached tries to find the given executable name in the $PATH, using a cache for faster access. Assumes that the $PATH environment variable has not changed since the last check.
Types ¶
This section is empty.