Making a config package for Generating keymappings
Following changes have been made:
1. Moving the getMusicDirectory() to config package
2. Moving the config.go to config package
3. Generating a Function Map that will be used for Generating keymappings in main.go
4. Using the config packge in main.go
5. First we are reading the user configuration values with
config.ReadConfig() and then we are reading the mappings with
config.ReadMappings() with the help of Function Map that is
generated.
This commit is contained in:
26
utils.go
26
utils.go
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -82,27 +80,3 @@ func formatString(a interface{}) string {
|
||||
return "Paused"
|
||||
}
|
||||
}
|
||||
|
||||
func getMusicDirectory() string {
|
||||
content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf")
|
||||
if err != nil {
|
||||
fmt.Println("No Config File for mpd Found")
|
||||
panic(err)
|
||||
}
|
||||
ab := string(content)
|
||||
maps := strings.Split(ab, "\n")
|
||||
for _, j := range maps {
|
||||
if strings.Contains(j, "music_directory") {
|
||||
s := strings.SplitAfter(strings.ReplaceAll(j, " ", ""), "y")[1]
|
||||
s = strings.ReplaceAll(s, "\t", "")
|
||||
d := ""
|
||||
for z, m := range s {
|
||||
if (z != 0) && (z != (len(s) - 1)) {
|
||||
d += string(m)
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user