Skip to content

Commit

Permalink
update initialConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed Apr 23, 2024
1 parent 31b05bb commit e7f93f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
47 changes: 20 additions & 27 deletions src/components/config_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"path/filepath"

"github.com/barasher/go-exiftool"
"github.com/pelletier/go-toml/v2"
"github.com/spf13/viper"
)
"github.com/pelletier/go-toml/v2")

func initialConfig(dir string) (toggleDotFileBool bool, firstFilePanelDir string) {
var err error
Expand All @@ -22,15 +20,8 @@ func initialConfig(dir string) (toggleDotFileBool bool, firstFilePanelDir string

loadHotkeysFile()

data, err := os.ReadFile(SuperFileMainDir + themeFolder + "/" + Config.Theme + ".toml")
if err != nil {
log.Fatalf("Theme file doesn't exist: %v", err)
}
loadThemeFile()

err = toml.Unmarshal(data, &theme)
if err != nil {
log.Fatalf("Error while decoding theme json( Your theme file may have errors ): %v", err)
}
toggleDotFileData, err := os.ReadFile(SuperFileDataDir + toggleDotFile)
if err != nil {
outPutLog("Error while reading toggleDotFile data error:", err)
Expand Down Expand Up @@ -60,33 +51,35 @@ func initialConfig(dir string) (toggleDotFileBool bool, firstFilePanelDir string
}

func loadConfigFile() {
viperConfig := viper.New()
viperConfig.SetConfigName("config")
viperConfig.SetConfigType("toml")
viperConfig.SetConfigFile(SuperFileMainDir + configFile)
err := viperConfig.ReadInConfig()
data, err := os.ReadFile(SuperFileMainDir + configFile)
if err != nil {
log.Fatalf("Config file doesn't exist: %v", err)
}
err = viperConfig.Unmarshal(&Config)
err = toml.Unmarshal(data, &Config)
if err != nil {
log.Fatalf("Error decoding config file( your config file may have misconfigured ): %v", err)
log.Fatalf("Error decoding config file ( your config file may have misconfigured ): %v", err)
}
}

func loadHotkeysFile() {

viperHotkeys := viper.New()
viperHotkeys.SetConfigName("hotkeys")
viperHotkeys.SetConfigType("toml")
viperHotkeys.SetConfigFile(SuperFileMainDir + hotkeysFile)

err := viperHotkeys.ReadInConfig()
data, err := os.ReadFile(SuperFileMainDir + hotkeysFile)
if err != nil {
log.Fatalf("Config file doesn't exist: %v", err)
}
err = viperHotkeys.Unmarshal(&hotkeys)
err = toml.Unmarshal(data, &hotkeys)
if err != nil {
log.Fatalf("Error decoding config file ( your config file may have misconfigured ): %v", err)
}
}

func loadThemeFile() {
data, err := os.ReadFile(SuperFileMainDir + themeFolder + "/" + Config.Theme + ".toml")
if err != nil {
log.Fatalf("Theme file doesn't exist: %v", err)
}

err = toml.Unmarshal(data, &theme)
if err != nil {
log.Fatalf("Error decoding hotkeys file( your config file may have misconfigured ): %v", err)
log.Fatalf("Error while decoding theme file( Your theme file may have errors ): %v", err)
}
}
2 changes: 1 addition & 1 deletion src/components/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type HotkeysType struct {
CompressFile []string `mapstructure:"compress_file"`
ToggleDotFile []string `mapstructure:"toggle_dot_file"`

OpenFileWithEditor []string `mapstructure:"oepn_file_with_editor`
OpenFileWithEditor []string `mapstructure:"oepn_file_with_editor"`
OpenCurrentDirectoryWithEditor []string `mapstructure:"open_current_directory_with_editor"`

Cancel []string `mapstructure:"cancel"`
Expand Down
2 changes: 1 addition & 1 deletion src/components/key_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func mainKey(msg string, m model, cmd tea.Cmd) (model, tea.Cmd) {
}()
case hotkeys.OpenFileWithEditor[0], hotkeys.OpenFileWithEditor[1]:
cmd = openFileWithEditor(m)
case hotkeys.OpenCurrentDirectoryWithEditor[0], hotkeys.OpenFileWithEditor[1]:
case hotkeys.OpenCurrentDirectoryWithEditor[0], hotkeys.OpenCurrentDirectoryWithEditor[1]:
cmd = openDirectoryWithEditor(m)
default:
m = normalAndBrowserModeKey(msg, m)
Expand Down

0 comments on commit e7f93f1

Please sign in to comment.