terminal: expand ~ in paths passed to 'source' (#3387)
This commit is contained in:
parent
5880f4cec9
commit
c958128f21
@ -19,6 +19,7 @@ import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"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>")
|
||||
}
|
||||
|
||||
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" {
|
||||
_, err := t.starlarkEnv.Execute(args, nil, "main", nil)
|
||||
return err
|
||||
}
|
||||
|
||||
if args == "-" {
|
||||
return t.starlarkEnv.REPL()
|
||||
}
|
||||
|
||||
return c.executeFile(t, args)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user