scriptlike

Utility to aid in script-like programs.

This is deliberately created as one file for easier usage in script-like programs.

Written in the D programming language. Tested with DMD 2.064.2 Licensed under The zlib/libpng License

Homepage: https://github.com/abscissa/scriptlike

API Reference: http://semitwist.com/scriptlike

Modules

core
module scriptlike.core
fail
module scriptlike.fail
file
module scriptlike.file
Scriptlike $(SCRIPTLIKE_VERSION)
interact
module scriptlike.interact

Handling of interaction with users via standard input.

only
module scriptlike.only
Scriptlike $(SCRIPTLIKE_VERSION)

Utility to aid in script-like programs.

path
module scriptlike.path
Scriptlike $(SCRIPTLIKE_VERSION)
process
module scriptlike.process
std
module scriptlike.std
Scriptlike $(SCRIPTLIKE_VERSION)

Utility to aid in script-like programs.

Public Imports

std.algorithm
public import std.algorithm;
Undocumented in source.
std.array
public import std.array;
Undocumented in source.
std.bigint
public import std.bigint;
Undocumented in source.
std.conv
public import std.conv;
Undocumented in source.
std.datetime
public import std.datetime;
Undocumented in source.
std.exception
public import std.exception;
Undocumented in source.
std.getopt
public import std.getopt;
Undocumented in source.
std.math
public import std.math;
Undocumented in source.
std.process
public import std.process;
Undocumented in source.
std.random
public import std.random;
Undocumented in source.
std.range
public import std.range;
Undocumented in source.
std.regex
public import std.regex;
Undocumented in source.
std.stdio
public import std.stdio;
Undocumented in source.
std.string
public import std.string;
Undocumented in source.
std.system
public import std.system;
Undocumented in source.
std.traits
public import std.traits;
Undocumented in source.
std.typecons
public import std.typecons;
Undocumented in source.
std.typetuple
public import std.typetuple;
Undocumented in source.
std.uni
public import std.uni;
Undocumented in source.
std.variant
public import std.variant;
Undocumented in source.

Members

Aliases

CaseSensitive
alias CaseSensitive = std.path.CaseSensitive
Undocumented in source.
FileException
alias FileException = std.file.FileException

Part of workaround for DMD Issue #12111

SpanMode
alias SpanMode = std.file.SpanMode
Undocumented in source.
attrIsDir
alias attrIsDir = std.file.attrIsDir
Undocumented in source.
attrIsFile
alias attrIsFile = std.file.attrIsFile
Undocumented in source.
attrIsSymlink
alias attrIsSymlink = std.file.attrIsSymlink
Undocumented in source.
buildNormalizedPath
alias buildNormalizedPath = std.path.buildNormalizedPath
Undocumented in source.
buildPath
alias buildPath = std.path.buildPath
Undocumented in source.
defaultExt
alias defaultExt = defaultExtension
Undocumented in source.
dirSeparator
alias dirSeparator = std.path.dirSeparator

Part of workaround for DMD Issue #12111

extOf
alias extOf = extension

Convenience aliases

getcwd
alias getcwd = std.file.getcwd
Undocumented in source.
isDirSeparator
alias isDirSeparator = std.path.isDirSeparator
Undocumented in source.
osDefaultCaseSensitivity
alias osDefaultCaseSensitivity = std.path.osDefaultCaseSensitivity
Undocumented in source.
pathSeparator
alias pathSeparator = std.path.pathSeparator
Undocumented in source.
setExt
alias setExt = setExtension
Undocumented in source.
stripExt
alias stripExt = stripExtension
Undocumented in source.
tempDir
alias tempDir = std.file.tempDir
Undocumented in source.
thisExePath
alias thisExePath = std.file.thisExePath
Undocumented in source.

Classes

Fail
class Fail

In your main(), catch this Fail exception, then output Fail.msg and return an error code.

Functions

absolutePath
Path!C absolutePath(Path!C path, string base)
Path!C absolutePath(Path!C path, Path!C base)

Just like std.path.absolutePath, but operates on Path.

absolutePath
string absolutePath(string path, string base)

Part of workaround for DMD Issue #12111

append
void append(Path!C name, void[] buffer)

Just like std.file.append, but takes a Path.

append
void append(char[] name, void[] buffer)

Part of workaround for DMD Issue #12111

baseName
Path!C baseName(Path!C path)
Path!C baseName(Path!C path, C1[] suffix)

Just like std.path.baseName, but operates on Path.

baseName
inout(C)[] baseName(inout(C)[] path)
inout(C)[] baseName(inout(C)[] path, C1[] suffix)

Part of workaround for DMD Issue #12111

buildNormalizedPathFixed
immutable(C)[] buildNormalizedPathFixed(const(C[])[] paths)

Like buildNormalizedPath, but if the result is the current directory, this returns "." instead of "". However, if all the inputs are "", or there are no inputs, this still returns "" just like buildNormalizedPath.

chdir
void chdir(char[] pathname)

Just like std.file.chdir, but echoes if scriptlikeTraceCommands is true.

chdir
void chdir(Path!C pathname)

Just like std.file.chdir, but takes a Path, and echoes if scriptlikeTraceCommands is true.

copy
void copy(char[] from, char[] to)

Just like std.file.copy, but echoes if scriptlikeTraceCommands is true.

copy
void copy(Path!C from, char[] to)
void copy(char[] from, Path!C to)

Just like std.file.copy, but takes Path, and echoes if scriptlikeTraceCommands is true.

copy
void copy(Path!C from, Path!C to)

Just like std.file.copy, but takes Path, and echoes if scriptlikeTraceCommands is true.

defaultExtension
Path!C defaultExtension(Path!C path, C2[] ext)
Path!C defaultExtension(Path!C path, Ext!C ext)

Just like std.path.defaultExtension, but operates on Path and optionally Ext.

defaultExtension
immutable(Unqual!C1)[] defaultExtension(C1[] path, C2[] ext)
dirEntries
auto dirEntries(string path, string pattern, SpanMode mode, bool followSymlink)

Part of workaround for DMD Issue #12111

dirEntries
auto dirEntries(string path, SpanMode mode, bool followSymlink)

Part of workaround for DMD Issue #12111

dirEntries
auto dirEntries(Path!C path, string pattern, SpanMode mode, bool followSymlink)

Just like std.file.dirEntries, but takes a Path.

dirEntries
auto dirEntries(Path!C path, SpanMode mode, bool followSymlink)

Just like std.file.dirEntries, but takes a Path.

dirName
Path!C dirName(Path!C path)

Just like std.path.dirName, but operates on Path.

dirName
C[] dirName(C[] path)

Part of workaround for DMD Issue #12111

driveName
Path!C driveName(Path!C path)

Just like std.path.driveName, but operates on Path.

driveName
inout(C)[] driveName(inout(C)[] path)

Part of workaround for DMD Issue #12111

escapeShellPath
string escapeShellPath(T str)
Undocumented in source. Be warned that the author may not have intended to support it.
exists
bool exists(char[] name)

Part of workaround for DMD Issue #12111

exists
bool exists(Path!C name)

Just like std.file.exists, but takes a Path.

existsAsDir
bool existsAsDir(Path!C path)

Checks if the path exists as a directory.

existsAsDir
bool existsAsDir(char[] path)

Checks if the path exists as a directory.

existsAsFile
bool existsAsFile(Path!C path)

Checks if the path exists as a file.

existsAsFile
bool existsAsFile(char[] path)

Checks if the path exists as a file.

existsAsSymlink
bool existsAsSymlink(Path!C path)

Checks if the path exists as a symlink.

existsAsSymlink
bool existsAsSymlink(char[] path)

Checks if the path exists as a symlink.

expandTilde
Path!C expandTilde(Path!C path)

Just like std.path.expandTilde, but operates on Path.

expandTilde
string expandTilde(string inputPath)

Part of workaround for DMD Issue #12111

ext
auto ext(T str)

Helper for creating an Ext.

extension
Ext!C extension(Path!C path)

Just like std.path.extension, but takes a Path and returns an Ext.

extension
inout(C)[] extension(inout(C)[] path)

Part of workaround for DMD Issue #12111

fail
void fail(string msg, string file, int line)

If you've set up your main() to handle the Fail exception (as shown in Fail's documentation, then call this to end your program with an error message in an exception-safe way.

filenameCharCmp
int filenameCharCmp(dchar a, dchar b)

Part of workaround for DMD Issue #12111

filenameCmp
int filenameCmp(Path!C path, Path!C2 filename2)
int filenameCmp(Path!C path, const(C2)[] filename2)
int filenameCmp(const(C)[] path, Path!C2[] filename2)

Just like std.path.filenameCmp, but operates on Path.

filenameCmp
int filenameCmp(const(C1)[] filename1, const(C2)[] filename2)

Part of workaround for DMD Issue #12111

getAttributes
uint getAttributes(char[] name)

Part of workaround for DMD Issue #12111

getAttributes
uint getAttributes(Path!C name)

Just like std.file.getAttributes, but takes a Path.

getLinkAttributes
uint getLinkAttributes(char[] name)

Part of workaround for DMD Issue #12111

getLinkAttributes
uint getLinkAttributes(Path!C name)

Just like std.file.getLinkAttributes, but takes a Path.

getSize
ulong getSize(char[] name)

Part of workaround for DMD Issue #12111

getSize
ulong getSize(Path!C name)

Just like std.file.getSize, but takes a Path.

getTimes
void getTimes(char[] name, SysTime accessTime, SysTime modificationTime)

Part of workaround for DMD Issue #12111

getTimes
void getTimes(Path!C name, SysTime accessTime, SysTime modificationTime)

Just like std.file.getTimes, but takes a Path.

getTimesWin
void getTimesWin(char[] name, SysTime fileCreationTime, SysTime fileAccessTime, SysTime fileModificationTime)

Part of workaround for DMD Issue #12111

getTimesWin
void getTimesWin(Path!C name, SysTime fileCreationTime, SysTime fileAccessTime, SysTime fileModificationTime)

Windows-only. Just like std.file.getTimesWin, but takes a Path.

globMatch
bool globMatch(Path!C path, const(C)[] pattern)

Just like std.path.globMatch, but operates on Path.

globMatch
bool globMatch(const(C)[] path, const(C)[] pattern)

Part of workaround for DMD Issue #12111

isAbsolute
bool isAbsolute(Path!C path)

Just like std.path.isAbsolute, but operates on Path.

isAbsolute
bool isAbsolute(C[] path)

Part of workaround for DMD Issue #12111

isRooted
bool isRooted(Path!C path)

Just like std.path.isRooted, but operates on Path.

isRooted
bool isRooted(C[] path)

Part of workaround for DMD Issue #12111

isValidFilename
bool isValidFilename(Path!C path)

Just like std.path.isValidFilename, but operates on Path.

isValidFilename
bool isValidFilename(C[] filename)

Part of workaround for DMD Issue #12111

isValidPath
bool isValidPath(Path!C path)

Just like std.path.isValidPath, but operates on Path.

isValidPath
bool isValidPath(C[] path)

Part of workaround for DMD Issue #12111

main
void main()
Undocumented in source. Be warned that the author may not have intended to support it.
mkdir
void mkdir(char[] pathname)

Just like std.file.mkdir, but echoes if scriptlikeTraceCommands is true.

mkdir
void mkdir(Path!C pathname)

Just like std.file.mkdir, but takes a Path, and echoes if scriptlikeTraceCommands is true.

mkdirRecurse
void mkdirRecurse(char[] pathname)

Just like std.file.mkdirRecurse, but echoes if scriptlikeTraceCommands is true.

mkdirRecurse
void mkdirRecurse(Path!C pathname)

Just like std.file.mkdirRecurse, but takes a Path, and echoes if scriptlikeTraceCommands is true.

path
auto path(T str)

Helper for creating a Path.

pathSplitter
auto pathSplitter(Path!C path)

Just like std.path.pathSplitter. Note this returns a range of strings, not a range of Path.

pathSplitter
ReturnType!(std.path.pathSplitter!C) pathSplitter(const(C)[] path)

Part of workaround for DMD Issue #12111

read
void[] read(Path!C name, size_t upTo)

Just like std.file.read, but takes a Path.

read
void[] read(char[] name, size_t upTo)

Part of workaround for DMD Issue #12111

readLink
string readLink(const(C)[] link)

Part of workaround for DMD Issue #12111

readLink
Path!C readLink(Path!C link)

Posix-only. Just like std.file.readLink, but operates on Path.

readText
S readText(char[] name)

Part of workaround for DMD Issue #12111

relativePath
string relativePath(string path, string base)

Part of workaround for DMD Issue #12111

relativePath
Path!C relativePath(Path!C path, Path!C base)

Just like std.path.relativePath, but operates on Path.

relativePath
Path!C relativePath(Path!C path, string base)

Just like std.path.relativePath, but operates on Path.

remove
void remove(Path!C name)

Just like std.file.remove, but takes a Path, and echoes if scriptlikeTraceCommands is true.

remove
void remove(char[] name)

Just like std.file.remove, but echoes if scriptlikeTraceCommands is true.

rename
void rename(char[] from, char[] to)

Just like std.file.rename, but echoes if scriptlikeTraceCommands is true.

rename
void rename(Path!C from, char[] to)
void rename(char[] from, Path!C to)

Just like std.file.rename, but takes Path, and echoes if scriptlikeTraceCommands is true.

rename
void rename(Path!C from, Path!C to)

Just like std.file.rename, but takes Path, and echoes if scriptlikeTraceCommands is true.

rmdir
void rmdir(Path!C pathname)

Just like std.file.rmdir, but takes a Path, and echoes if scriptlikeTraceCommands is true.

rmdir
void rmdir(char[] pathname)

Just like std.file.rmdir, but echoes if scriptlikeTraceCommands is true.

rmdirRecurse
void rmdirRecurse(Path!C pathname)

Just like std.file.rmdirRecurse, but takes a Path, and echoes if scriptlikeTraceCommands is true.

rmdirRecurse
void rmdirRecurse(char[] pathname)

Just like std.file.rmdirRecurse, but echoes if scriptlikeTraceCommands is true.

rootName
inout(C)[] rootName(inout(C)[] path)

Part of workaround for DMD Issue #12111

rootName
Path!C rootName(Path!C path)

Just like std.path.rootName, but operates on Path.

runShell
int runShell(string command)
int runShell(Path!C workingDirectory, string command)

Runs a command, through the system's command shell interpreter, in typical shell-script style: Synchronously, with the command's stdout/in/err automatically forwarded through your program's stdout/in/err.

setExtension
immutable(C1)[] setExtension(immutable(C1)[] path, const(C2)[] ext)

Part of workaround for DMD Issue #12111

setExtension
immutable(Unqual!C1)[] setExtension(C1[] path, C2[] ext)

Part of workaround for DMD Issue #12111

setExtension
Path!C setExtension(Path!C path, Ext!C ext)

Just like std.path.setExtension, but operates on Path.

setExtension
Path!C setExtension(Path!C path, const(C2)[] ext)

Just like std.path.setExtension, but operates on Path.

setTimes
void setTimes(Path!C name, SysTime accessTime, SysTime modificationTime)

Just like std.file.setTimes, but takes a Path.

setTimes
void setTimes(char[] name, SysTime accessTime, SysTime modificationTime)

Part of workaround for DMD Issue #12111

slurp
Select!(Types.length == 1, Types[0][], Tuple!(Types)[]) slurp(string filename, char[] format)

Part of workaround for DMD Issue #12111

stripDrive
inout(C)[] stripDrive(inout(C)[] path)

Part of workaround for DMD Issue #12111

stripDrive
Path!C stripDrive(Path!C path)

Just like std.path.stripDrive, but operates on Path.

stripExtension
inout(C)[] stripExtension(inout(C)[] path)

Part of workaround for DMD Issue #12111

stripExtension
Path!C stripExtension(Path!C path)

Just like std.path.stripExtension, but operates on Path.

symlink
void symlink(Path!C1 original, Path!C2 link)
void symlink(const(C1)[] original, Path!C2 link)
void symlink(Path!C1 original, const(C2)[] link)

Posix-only. Just like std.file.symlink, but takes Path, and echoes if scriptlikeTraceCommands is true.

symlink
void symlink(const(C1)[] original, const(C2)[] link)

Just like std.file.symlink, but echoes if scriptlikeTraceCommands is true.

timeLastModified
SysTime timeLastModified(Path!C name)

Just like std.file.timeLastModified, but takes a Path.

timeLastModified
SysTime timeLastModified(Path!C name, SysTime returnIfMissing)

Just like std.file.timeLastModified, but takes a Path.

timeLastModified
SysTime timeLastModified(char[] name)
SysTime timeLastModified(char[] name, SysTime returnIfMissing)

Part of workaround for DMD Issue #12111

tryCopy
bool tryCopy(T1 from, T2 to)

If 'from' exists, then copy. Otherwise do nothing.

tryMkdir
bool tryMkdir(T name)

If 'name' doesn't already exist, then mkdir. Otherwise do nothing.

tryMkdirRecurse
bool tryMkdirRecurse(T name)

If 'name' doesn't already exist, then mkdirRecurse. Otherwise do nothing.

tryRemove
bool tryRemove(T name)

If 'name' exists, then remove. Otherwise do nothing.

tryRename
bool tryRename(T1 from, T2 to)

If 'from' exists, then rename. Otherwise do nothing.

tryRmdir
bool tryRmdir(T name)

If 'name' exists, then rmdir. Otherwise do nothing.

tryRmdirRecurse
bool tryRmdirRecurse(T name)

If 'name' exists, then rmdirRecurse. Otherwise do nothing.

trySymlink
bool trySymlink(T1 original, T2 link)

If 'original' exists, then symlink. Otherwise do nothing.

write
void write(char[] name, void[] buffer)

Part of workaround for DMD Issue #12111

write
void write(Path!C name, void[] buffer)

Just like std.file.write, but takes a Path.

Properties

isDir
bool isDir [@property getter]

Just like std.file.isDir, but takes a Path.

isDir
bool isDir [@property getter]

Part of workaround for DMD Issue #12111

isFile
bool isFile [@property getter]

Just like std.file.isFile, but takes a Path.

isFile
bool isFile [@property getter]

Part of workaround for DMD Issue #12111

isSymlink
bool isSymlink [@property getter]

Just like std.file.isSymlink, but takes a Path.

isSymlink
bool isSymlink [@property getter]

Part of workaround for DMD Issue #12111

Structs

Ext
struct Ext(C = char)

Represents a file extension.

Path
struct Path(C = char)

Represents a filesystem path. The path is always kept normalized automatically (as performed by buildNormalizedPathFixed).

Templates

readText
template readText(S = string)

Just like std.file.readText, but takes a Path.

slurp
template slurp(Types...)

Just like std.file.slurp, but takes a Path.

Variables

scriptlikeTraceCommands
bool scriptlikeTraceCommands;

If true, all commands will be echoed to stdout

Meta