Skip to content

Commit

Permalink
Update AliasPath and ExpandPath function to use Global InitDirectory …
Browse files Browse the repository at this point in the history
…variable, initialised from config file with SetupDirectory()
  • Loading branch information
SwayKh committed Sep 20, 2024
1 parent 1a8a0ed commit c643d95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
HomeDirectory string
ConfigPath string
Configuration appConfig
InitDirectory string
)

type appConfig struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func CheckFile(path string) (bool, os.FileInfo, error) {
// Expand the ~ and $init_directory variables to their respective values
func expandPath(path string) string {
if strings.HasPrefix(path, "$init_directory") {
path = strings.Replace(path, "$init_directory", Configuration.InitDirectory, 1)
path = strings.Replace(path, "$init_directory", InitDirectory, 1)
}
if strings.HasPrefix(path, "~") {
path = strings.Replace(path, "~", HomeDirectory, 1)
Expand All @@ -36,8 +36,8 @@ func aliasPath(path string, skipInitDir bool) string {
if strings.HasPrefix(path, HomeDirectory) {
path = strings.Replace(path, HomeDirectory, "~", 1)
}
if !skipInitDir && strings.HasPrefix(path, Configuration.InitDirectory) {
path = strings.Replace(path, Configuration.InitDirectory, "$init_directory", 1)
if !skipInitDir && strings.HasPrefix(path, InitDirectory) {
path = strings.Replace(path, InitDirectory, "$init_directory", 1)
}

return path
Expand Down

0 comments on commit c643d95

Please sign in to comment.