mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
a3f4384495
The elvdocs still use the old format (#elvdoc:fn or #elvdoc:var) for now, but will be changed to "fn" and "var" forms soon. Also remove the accidentally committed cmd/mvelvdoc. It has been used to perform the conversion automatically but is not supposed to be committed.
41 lines
620 B
Go
41 lines
620 B
Go
package eval
|
|
|
|
import (
|
|
"src.elv.sh/pkg/eval/errs"
|
|
"src.elv.sh/pkg/fsutil"
|
|
)
|
|
|
|
// Filesystem commands.
|
|
|
|
func init() {
|
|
addBuiltinFns(map[string]any{
|
|
// Directory
|
|
"cd": cd,
|
|
|
|
// Path
|
|
"tilde-abbr": tildeAbbr,
|
|
})
|
|
}
|
|
|
|
func cd(fm *Frame, args ...string) error {
|
|
var dir string
|
|
switch len(args) {
|
|
case 0:
|
|
var err error
|
|
dir, err = getHome("")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
case 1:
|
|
dir = args[0]
|
|
default:
|
|
return errs.ArityMismatch{What: "arguments", ValidLow: 0, ValidHigh: 1, Actual: len(args)}
|
|
}
|
|
|
|
return fm.Evaler.Chdir(dir)
|
|
}
|
|
|
|
func tildeAbbr(path string) string {
|
|
return fsutil.TildeAbbr(path)
|
|
}
|