Skip to content

Commit 1498c92

Browse files
committed
auto update config if missing config
1 parent 39120bb commit 1498c92

File tree

4 files changed

+104
-71
lines changed

4 files changed

+104
-71
lines changed

Diff for: src/components/config_function.go

+35-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log"
55
"os"
66
"path/filepath"
7+
"reflect"
78

89
"github.com/barasher/go-exiftool"
910
"github.com/pelletier/go-toml/v2"
@@ -54,30 +55,60 @@ func initialConfig(dir string) (toggleDotFileBool bool, firstFilePanelDir string
5455
func loadConfigFile() {
5556

5657
_ = toml.Unmarshal([]byte(ConfigTomlString), &Config)
58+
tempForCheckMissingConfig := ConfigType{}
5759

5860
data, err := os.ReadFile(SuperFileMainDir + configFile)
5961
if err != nil {
6062
log.Fatalf("Config file doesn't exist: %v", err)
6163
}
64+
65+
_ = toml.Unmarshal(data, &tempForCheckMissingConfig)
6266
err = toml.Unmarshal(data, &Config)
6367
if err != nil {
6468
log.Fatalf("Error decoding config file ( your config file may have misconfigured ): %v", err)
6569
}
70+
71+
if !reflect.DeepEqual(Config, tempForCheckMissingConfig) {
72+
tomlData, err := toml.Marshal(Config)
73+
if err != nil {
74+
log.Fatalf("Error encoding config: %v", err)
75+
}
76+
77+
err = os.WriteFile(SuperFileMainDir+configFile, tomlData, 0644)
78+
if err != nil {
79+
log.Fatalf("Error writing config file: %v", err)
80+
}
81+
}
6682
}
6783

6884
func loadHotkeysFile() {
69-
70-
_ = toml.Unmarshal([]byte(HotkeysTomlString), &hotkeys)
7185

86+
_ = toml.Unmarshal([]byte(HotkeysTomlString), &hotkeys)
87+
tempForCheckMissingConfig := HotkeysType{}
7288
data, err := os.ReadFile(SuperFileMainDir + hotkeysFile)
73-
89+
7490
if err != nil {
7591
log.Fatalf("Config file doesn't exist: %v", err)
7692
}
93+
94+
_ = toml.Unmarshal(data, &tempForCheckMissingConfig)
7795
err = toml.Unmarshal(data, &hotkeys)
7896
if err != nil {
79-
log.Fatalf("Error decoding config file ( your config file may have misconfigured ): %v", err)
97+
log.Fatalf("Error decoding hotkeys file ( your config file may have misconfigured ): %v", err)
98+
}
99+
100+
if !reflect.DeepEqual(hotkeys, tempForCheckMissingConfig) {
101+
tomlData, err := toml.Marshal(hotkeys)
102+
if err != nil {
103+
log.Fatalf("Error encoding hotkeys: %v", err)
104+
}
105+
106+
err = os.WriteFile(SuperFileMainDir+hotkeysFile, tomlData, 0644)
107+
if err != nil {
108+
log.Fatalf("Error writing hotkeys file: %v", err)
109+
}
80110
}
111+
81112
}
82113

83114
func loadThemeFile() {

Diff for: src/components/config_type.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -102,49 +102,52 @@ type ThemeType struct {
102102

103103
// Configuration settings
104104
type ConfigType struct {
105-
Theme string `toml:"theme"`
106-
FooterPanelList []string `toml:"footer_panel_list"`
107-
Metadata bool `toml:"metadata"`
105+
Theme string `toml:"theme" comment:"change your theme"`
106+
FooterPanelList []string `toml:"footer_panel_list" comment:"\nuseless for now"`
107+
Metadata bool `toml:"metadata" comment:"\n==========PLUGINS========== #\n\nShow more detailed metadata, please install exiftool before enabling this plugin!"`
108108
}
109109

110110
type HotkeysType struct {
111-
Quit []string `toml:"quit"`
111+
Quit []string `toml:"quit" comment:"Here is global, all global key cant conflicts with other hotkeys"`
112112

113-
ListUp []string `toml:"list_up"`
113+
ListUp []string `toml:"list_up" comment:"\n"`
114114
ListDown []string `toml:"list_down"`
115115

116-
PinnedDirectory []string `toml:"pinned_directory"`
116+
PinnedDirectory []string `toml:"pinned_directory" comment:"\n"`
117117

118-
CloseFilePanel []string `toml:"close_file_panel"`
118+
CloseFilePanel []string `toml:"close_file_panel" comment:"\n"`
119119
CreateNewFilePanel []string `toml:"create_new_file_panel"`
120-
NextFilePanel []string `toml:"next_file_panel"`
120+
121+
NextFilePanel []string `toml:"next_file_panel" comment:"\n"`
121122
PreviousFilePanel []string `toml:"previous_file_panel"`
122123
FocusOnProcessBar []string `toml:"focus_on_process_bar"`
123124
FocusOnSideBar []string `toml:"focus_on_side_bar"`
124125
FocusOnMetaData []string `toml:"focus_on_meta_data"`
125-
ChangePanelMode []string `toml:"change_panel_mode"`
126-
FilePanelDirectoryCreate []string `toml:"file_panel_directory_create"`
126+
127+
ChangePanelMode []string `toml:"change_panel_mode" comment:"\n"`
128+
129+
FilePanelDirectoryCreate []string `toml:"file_panel_directory_create" comment:"\n"`
127130
FilePanelFileCreate []string `toml:"file_panel_file_create"`
128131
FilePanelItemRename []string `toml:"file_panel_item_rename"`
129132
PasteItem []string `toml:"paste_item"`
130133
ExtractFile []string `toml:"extract_file"`
131134
CompressFile []string `toml:"compress_file"`
132135
ToggleDotFile []string `toml:"toggle_dot_file"`
133136

134-
OpenFileWithEditor []string `toml:"oepn_file_with_editor"`
137+
OpenFileWithEditor []string `toml:"oepn_file_with_editor" comment:"\n"`
135138
OpenCurrentDirectoryWithEditor []string `toml:"open_current_directory_with_editor"`
136139

137-
Cancel []string `toml:"cancel"`
140+
Cancel []string `toml:"cancel" comment:"\nThese hotkeys do not conflict with any other keys (including global hotkey)"`
138141
Confirm []string `toml:"confirm"`
139142

140-
DeleteItem []string `toml:"delete_item"`
143+
DeleteItem []string `toml:"delete_item" comment:"\nHere is normal mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)"`
141144
SelectItem []string `toml:"select_item"`
142145
ParentDirectory []string `toml:"parent_directory"`
143146
CopySingleItem []string `toml:"copy_single_item"`
144147
CutSingleItem []string `toml:"cut_single_item"`
145148
SearchBar []string `toml:"search_bar"`
146149

147-
FilePanelSelectModeItemSingleSelect []string `toml:"file_panel_select_mode_item_single_select"`
150+
FilePanelSelectModeItemSingleSelect []string `toml:"file_panel_select_mode_item_single_select" comment:"\nHere is select mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)"`
148151
FilePanelSelectModeItemSelectDown []string `toml:"file_panel_select_mode_item_select_down"`
149152
FilePanelSelectModeItemSelectUp []string `toml:"file_panel_select_mode_item_select_up"`
150153
FilePanelSelectModeItemDelete []string `toml:"file_panel_select_mode_item_delete"`

Diff for: src/components/default_config.go

+52-53
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
11
package components
22

33
var HotkeysTomlString string = `# Here is global, all global key cant conflicts with other hotkeys
4-
quit = ["esc", "q"]
5-
6-
list_up = ["up", "k"]
7-
list_down = ["down", "j"]
8-
9-
pinned_directory = ["ctrl+p", ""]
10-
11-
close_file_panel = ["ctrl+w", ""]
12-
create_new_file_panel = ["ctrl+n", ""]
13-
14-
next_file_panel = ["tab", "L"]
15-
previous_file_panel = ["shift+left", "H"]
16-
focus_on_process_bar = ["p", ""]
17-
focus_on_side_bar = ["b", ""]
18-
focus_on_meta_data = ["m", ""]
19-
20-
change_panel_mode = ["v", ""]
21-
22-
file_panel_directory_create = ["f", ""]
23-
file_panel_file_create = ["c", ""]
24-
file_panel_item_rename = ["r", ""]
25-
paste_item = ["ctrl+v", ""]
26-
extract_file = ["ctrl+e", ""]
27-
compress_file = ["ctrl+r", ""]
28-
29-
oepn_file_with_editor = ["e", ""]
30-
open_current_directory_with_editor = ["E", ""]
31-
32-
toggle_dot_file = ["ctrl+h", ""]
33-
4+
quit = ['esc', 'q']
5+
#
6+
list_up = ['up', 'k']
7+
list_down = ['down', 'j']
8+
#
9+
pinned_directory = ['ctrl+p', '']
10+
#
11+
close_file_panel = ['ctrl+w', '']
12+
create_new_file_panel = ['ctrl+n', '']
13+
#
14+
next_file_panel = ['tab', 'L']
15+
previous_file_panel = ['shift+left', 'H']
16+
focus_on_process_bar = ['p', '']
17+
focus_on_side_bar = ['b', '']
18+
focus_on_meta_data = ['m', '']
19+
#
20+
change_panel_mode = ['v', '']
21+
#
22+
file_panel_directory_create = ['f', '']
23+
file_panel_file_create = ['c', '']
24+
file_panel_item_rename = ['r', '']
25+
paste_item = ['ctrl+v', '']
26+
extract_file = ['ctrl+e', '']
27+
compress_file = ['ctrl+r', '']
28+
toggle_dot_file = ['ctrl+h', '']
29+
#
30+
oepn_file_with_editor = ['e', '']
31+
open_current_directory_with_editor = ['E', '']
32+
#
3433
# These hotkeys do not conflict with any other keys (including global hotkey)
35-
cancel = ["ctrl+c", "esc"]
36-
confirm = ["enter", ""]
37-
34+
cancel = ['ctrl+c', 'esc']
35+
confirm = ['enter', '']
36+
#
3837
# Here is normal mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)
39-
delete_item = ["ctrl+d", ""]
40-
select_item = ["enter", "l"]
41-
parent_directory = ["h", "backspace"]
42-
copy_single_item = ["ctrl+c", ""]
43-
cut_single_item = ["ctrl+x", ""]
44-
search_bar = ["ctrl+f", ""]
45-
38+
delete_item = ['ctrl+d', '']
39+
select_item = ['enter', 'l']
40+
parent_directory = ['h', 'backspace']
41+
copy_single_item = ['ctrl+c', '']
42+
cut_single_item = ['ctrl+x', '']
43+
search_bar = ['ctrl+f', '']
44+
#
4645
# Here is select mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)
47-
file_panel_select_mode_item_single_select = ["enter", "l"]
48-
file_panel_select_mode_item_select_down = ["shift+down", "J"]
49-
file_panel_select_mode_item_select_up = ["shift+up", "K"]
50-
file_panel_select_mode_item_delete = ["ctrl+d", "delete"]
51-
file_panel_select_mode_item_copy = ["ctrl+c", ""]
52-
file_panel_select_mode_item_cut = ["ctrl+x", ""]
53-
file_panel_select_all_item = ["ctrl+a", ""]
46+
file_panel_select_mode_item_single_select = ['enter', 'l']
47+
file_panel_select_mode_item_select_down = ['shift+down', 'J']
48+
file_panel_select_mode_item_select_up = ['shift+up', 'K']
49+
file_panel_select_mode_item_delete = ['ctrl+d', 'delete']
50+
file_panel_select_mode_item_copy = ['ctrl+c', '']
51+
file_panel_select_mode_item_cut = ['ctrl+x', '']
52+
file_panel_select_all_item = ['ctrl+a', '']
5453
`
5554

5655
var ConfigTomlString string = `# change your theme
57-
theme = "catpuccin"
58-
56+
theme = 'catpuccin'
57+
#
5958
# useless for now
60-
footer_panel_list = ["processes", "metadata", "clipboard"]
61-
59+
footer_panel_list = ['processessssssssssss', 'metadata', 'clipboard']
60+
#
6261
# ==========PLUGINS========== #
63-
62+
#
6463
# Show more detailed metadata, please install exiftool before enabling this plugin!
65-
metadata = false
64+
metadata = true
6665
`

Diff for: src/main

12.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)