fix(config): resolve path for all shells

This commit is contained in:
Jan De Dobbeleer 2021-12-30 15:39:30 +01:00 committed by Jan De Dobbeleer
parent 5549e0d7ad
commit 7aaa7b110f

View file

@ -164,6 +164,7 @@ type environment struct {
func (env *environment) init(args *args) {
env.args = args
env.resolveConfigPath()
env.cmdCache = &commandCache{
commands: newConcurrentMap(),
}
@ -175,6 +176,23 @@ func (env *environment) init(args *args) {
env.fileCache.init(env.getCachePath())
}
func (env *environment) resolveConfigPath() {
if env.args == nil || env.args.Config == nil {
return
}
configFile := *env.args.Config
if strings.HasPrefix(configFile, "~") {
configFile = strings.TrimPrefix(configFile, "~")
configFile = filepath.Join(env.homeDir(), configFile)
}
if !filepath.IsAbs(configFile) {
if absConfigFile, err := filepath.Abs(configFile); err == nil {
configFile = absConfigFile
}
}
*env.args.Config = filepath.Clean(configFile)
}
func (env *environment) trace(start time.Time, function string, args ...string) {
if !env.debug {
return