Add -is-dir.

This commit is contained in:
Qi Xiao 2017-09-19 00:42:38 +01:00
parent 437953f4b8
commit 9d07cd9eb4

View File

@ -179,6 +179,9 @@ func init() {
{"eval-symlinks", WrapStringToStringError(filepath.EvalSymlinks)},
{"tilde-abbr", tildeAbbr},
// File types
{"-is-dir", isDir},
// Boolean operations
{"bool", boolFn},
{"not", not},
@ -1182,6 +1185,20 @@ func tildeAbbr(ec *EvalCtx, args []Value, opts map[string]Value) {
out <- String(util.TildeAbbr(path))
}
func isDir(ec *EvalCtx, args []Value, opts map[string]Value) {
var pathv String
ScanArgs(args, &pathv)
path := string(pathv)
TakeNoOpt(opts)
ec.OutputChan() <- Bool(isDirInner(path))
}
func isDirInner(path string) bool {
fi, err := os.Stat(path)
return err == nil && fi.Mode().IsDir()
}
func boolFn(ec *EvalCtx, args []Value, opts map[string]Value) {
var v Value
ScanArgs(args, &v)