mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
31 lines
553 B
Go
31 lines
553 B
Go
package eval
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/elves/elvish/daemon/api"
|
|
)
|
|
|
|
// PwdVariable is a variable whose value always reflects the current working
|
|
// directory. Setting it changes the current working directory.
|
|
type PwdVariable struct {
|
|
daemon *api.Client
|
|
}
|
|
|
|
var _ Variable = PwdVariable{}
|
|
|
|
func (PwdVariable) Get() Value {
|
|
pwd, err := os.Getwd()
|
|
maybeThrow(err)
|
|
return String(pwd)
|
|
}
|
|
|
|
func (pwd PwdVariable) Set(v Value) {
|
|
path, ok := v.(String)
|
|
if !ok {
|
|
throw(ErrPathMustBeString)
|
|
}
|
|
err := Chdir(string(path), pwd.daemon)
|
|
maybeThrow(err)
|
|
}
|