mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
Add -is-dir.
This commit is contained in:
parent
437953f4b8
commit
9d07cd9eb4
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user