github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/eval/builtin_fn_fs.go (about)

     1  package eval
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  
     7  	"github.com/u-root/u-root/cmds/elvish/util"
     8  )
     9  
    10  // Filesystem.
    11  
    12  var ErrStoreNotConnected = errors.New("store not connected")
    13  
    14  func init() {
    15  	addBuiltinFns(map[string]interface{}{
    16  		// Directory
    17  		"cd":         cd,
    18  		"tilde-abbr": tildeAbbr,
    19  	})
    20  }
    21  
    22  func cd(fm *Frame, args ...string) error {
    23  	var dir string
    24  	switch len(args) {
    25  	case 0:
    26  		dir = mustGetHome("")
    27  	case 1:
    28  		dir = args[0]
    29  	default:
    30  		return ErrArgs
    31  	}
    32  
    33  	return fm.Chdir(dir)
    34  }
    35  
    36  func dirs(fm *Frame) error {
    37  	return nil
    38  }
    39  
    40  func tildeAbbr(path string) string {
    41  	return util.TildeAbbr(path)
    42  }
    43  
    44  func isDir(path string) bool {
    45  	fi, err := os.Stat(path)
    46  	return err == nil && fi.Mode().IsDir()
    47  }