update expandPath for create command

parent b1fa9c96
......@@ -180,11 +180,24 @@ func loadConfig(path string) (*Config, error) {
func expandPath(path, name string) string {
home := os.Getenv("HOME")
if strings.HasPrefix(path, "~") {
path = filepath.Join(os.Getenv("HOME"), path[1:])
user := os.Getenv("USER")
hostname, _ := os.Hostname()
replacements := map[string]string{
"~": home,
"{home}": home,
"{user}": user,
"{name}": name,
"{hostname}": hostname,
"{config}": filepath.Join(home, ".config"),
"{ximperconf}": "/etc/ximperdistro",
}
path = strings.ReplaceAll(path, "{home}", home)
return strings.ReplaceAll(path, "{name}", name)
for k, v := range replacements {
path = strings.ReplaceAll(path, k, v)
}
return path
}
func commandExists(name string) bool {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment