-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default home directory behavior
- Loading branch information
Showing
15 changed files
with
136 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build darwin | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/kirsle/configdir" | ||
) | ||
|
||
func ReplaceHome(origin string) (string, error) { | ||
configPath, err := HomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
origin = strings.ReplaceAll(origin, "$HOME", configPath) | ||
fmt.Printf("medict app: ReplaceHome dictionary dir %s\n", origin) | ||
return origin, nil | ||
} | ||
|
||
func HomeDir() (string, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", fmt.Errorf("userhomedir err: %s", err.Error()) | ||
} | ||
configPath := filepath.Join(home, ".medict") | ||
|
||
err = configdir.MakePath(configPath) | ||
if err != nil { | ||
return "", fmt.Errorf("base home dir mkall failed, %s", err.Error()) | ||
} | ||
|
||
//configPath := configdir.LocalConfig("medict") | ||
//fmt.Printf("medict app: HomeDir %s\n", configPath) | ||
//err := configdir.MakePath(configPath) // Ensure it exists. | ||
//if err != nil { | ||
// return "", fmt.Errorf("base home dir mkall failed, %s", err.Error()) | ||
//} | ||
return configPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build linux | ||
|
||
package utils | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/kirsle/configdir" | ||
) | ||
|
||
func ReplaceHome(origin string) (string, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return origin, err | ||
} | ||
|
||
origin = strings.ReplaceAll(origin, "$HOME", home) | ||
return origin, nil | ||
} | ||
|
||
func HomeDir() (string, error) { | ||
configPath := configdir.LocalConfig("medict") | ||
err := configdir.MakePath(configPath) // Ensure it exists. | ||
if err != nil { | ||
return "", err | ||
} | ||
return configPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package utils | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/kirsle/configdir" | ||
) | ||
|
||
func ReplaceHome(origin string) (string, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return origin, err | ||
} | ||
|
||
origin = strings.ReplaceAll(origin, "$HOME", home) | ||
return origin, nil | ||
} | ||
|
||
func HomeDir() (string, error) { | ||
configPath := configdir.LocalConfig("medict") | ||
err := configdir.MakePath(configPath) // Ensure it exists. | ||
if err != nil { | ||
return "", err | ||
} | ||
return configPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters