terminal: expand ~ in paths passed to 'source' (#3387)
This commit is contained in:
parent
5880f4cec9
commit
c958128f21
@ -19,6 +19,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -2451,15 +2452,26 @@ func (c *Commands) sourceCommand(t *Term, ctx callContext, args string) error {
|
|||||||
return fmt.Errorf("wrong number of arguments: source <filename>")
|
return fmt.Errorf("wrong number of arguments: source <filename>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args == "-" {
|
||||||
|
return t.starlarkEnv.REPL()
|
||||||
|
}
|
||||||
|
|
||||||
|
if runtime.GOOS != "windows" && strings.HasPrefix(args, "~") {
|
||||||
|
home, err := os.UserHomeDir()
|
||||||
|
if err == nil {
|
||||||
|
if args == "~" {
|
||||||
|
args = home
|
||||||
|
} else if strings.HasPrefix(args, "~/") {
|
||||||
|
args = filepath.Join(home, args[2:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if filepath.Ext(args) == ".star" {
|
if filepath.Ext(args) == ".star" {
|
||||||
_, err := t.starlarkEnv.Execute(args, nil, "main", nil)
|
_, err := t.starlarkEnv.Execute(args, nil, "main", nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if args == "-" {
|
|
||||||
return t.starlarkEnv.REPL()
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.executeFile(t, args)
|
return c.executeFile(t, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user