Fixes #33
Also mentioned at (https://github.com/aditya-K2/gomp/issues/1#issuecomment-1205090265) `~` is not expanded to home directory, Hence adding an internal check for the same.
This commit is contained in:
parent
6830b5379f
commit
29b796a552
@ -29,15 +29,23 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ReadConfig() {
|
func ReadConfig() {
|
||||||
|
|
||||||
for k, v := range defaults {
|
for k, v := range defaults {
|
||||||
viper.SetDefault(k, v)
|
viper.SetDefault(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.AddConfigPath(HOME_DIR + "/.config/gomp")
|
viper.AddConfigPath(HOME_DIR + "/.config/gomp")
|
||||||
|
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Could Not Read Config file.")
|
fmt.Println("Could Not Read Config file.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expanding ~ to the User's Home Directory
|
||||||
|
viper.Set("MUSIC_DIRECTORY", utils.ExpandHomeDir(viper.GetString("MUSIC_DIRECTORY")))
|
||||||
|
viper.Set("DEFAULT_IMAGE_PATH", utils.ExpandHomeDir(viper.GetString("DEFAULT_IMAGE_PATH")))
|
||||||
|
viper.Set("CACHE_DIR", utils.ExpandHomeDir(viper.GetString("CACHE_DIR")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateKeyMap(funcMap map[string]func()) {
|
func GenerateKeyMap(funcMap map[string]func()) {
|
||||||
|
@ -2,6 +2,8 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -117,6 +119,17 @@ func CheckDirectoryFmt(path string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExpandHomeDir(path string) string {
|
||||||
|
HOME_DIR, _ := os.UserHomeDir()
|
||||||
|
if strings.HasPrefix(path, "~/") {
|
||||||
|
return filepath.Join(HOME_DIR, path[1:])
|
||||||
|
} else if path == "~" {
|
||||||
|
return HOME_DIR
|
||||||
|
} else {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetMatchedString(a []int, s, color string) string {
|
func GetMatchedString(a []int, s, color string) string {
|
||||||
// The Matches are sorted so we just have to traverse the Matches and if the two adjacent matches are not consecutive
|
// The Matches are sorted so we just have to traverse the Matches and if the two adjacent matches are not consecutive
|
||||||
// then we append the color string at the start + offset and the nulcol ( reset ) at end + offset + 1 and then reset
|
// then we append the color string at the start + offset and the nulcol ( reset ) at end + offset + 1 and then reset
|
||||||
|
Loading…
Reference in New Issue
Block a user