diff --git a/chat.proto b/chat.proto index 1cc083a..4ac1da6 100644 --- a/chat.proto +++ b/chat.proto @@ -15,7 +15,7 @@ message Table { // `autogenpb:nomute enum Who { NOONE = 0; - GEMINI = 1; + REGEX = 1; USER = 2; } diff --git a/config.go b/config.go index b68af0f..bdfa08e 100644 --- a/config.go +++ b/config.go @@ -14,12 +14,12 @@ import ( "go.wit.com/log" ) -// write to ~/.config/gemini/ unless ENV{GEMINI_HOME} is set +// write to ~/.config/regex/ unless ENV{REGEX_HOME} is set func (all *Chats) ConfigSave() error { - if os.Getenv("GEMINI_HOME") == "" { + if os.Getenv("REGEX_HOME") == "" { homeDir, _ := os.UserHomeDir() - fullpath := filepath.Join(homeDir, ".config/gemini") - os.Setenv("GEMINI_HOME", fullpath) + fullpath := filepath.Join(homeDir, ".config/regex") + os.Setenv("REGEX_HOME", fullpath) } if all == nil { log.Warn("chatpb all == nil") @@ -52,7 +52,7 @@ func (all *Chats) ConfigSave() error { data, err = cleanChats.Marshal() // Retry with the clean object if err == nil { log.Info("chatpb.ConfigSave() pb.Marshal() worked after validation len", len(cleanChats.Chats), "chats") - configWrite("gemini.pb", data) + configWrite("regex.pb", data) return nil } } @@ -60,12 +60,12 @@ func (all *Chats) ConfigSave() error { } // --- Backup Logic --- - filename := filepath.Join(os.Getenv("GEMINI_HOME"), "gemini.pb") + filename := filepath.Join(os.Getenv("REGEX_HOME"), "regex.pb") if _, err := os.Stat(filename); err == nil { // File exists, so back it up. dir := filepath.Dir(filename) timestamp := time.Now().Format("20060102-150405") - backupFilename := fmt.Sprintf("gemini.%s.pb", timestamp) + backupFilename := fmt.Sprintf("regex.%s.pb", timestamp) backupPath := filepath.Join(dir, backupFilename) if err := os.Rename(filename, backupPath); err != nil { log.Warn("Could not backup config file:", err) @@ -73,11 +73,11 @@ func (all *Chats) ConfigSave() error { } // --- End Backup Logic --- - if err := configWrite("gemini.pb", data); err != nil { + if err := configWrite("regex.pb", data); err != nil { log.Infof("chatpb.ConfigSave() failed len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data)) return err } - configWrite("gemini.text", []byte(cleanChats.FormatTEXT())) + configWrite("regex.text", []byte(cleanChats.FormatTEXT())) log.Infof("chatpb.ConfigSave() worked len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data)) return nil } @@ -96,29 +96,29 @@ func (all *Chats) tryValidate() error { return nil } -// load the gemini.pb file. I shouldn't really matter if this +// load the regex.pb file. I shouldn't really matter if this // fails. the file should be autogenerated. This is used // locally just for speed func (all *Chats) ConfigLoad() error { - if os.Getenv("GEMINI_HOME") == "" { + if os.Getenv("REGEX_HOME") == "" { homeDir, _ := os.UserHomeDir() - fullpath := filepath.Join(homeDir, ".config/gemini") - os.Setenv("GEMINI_HOME", fullpath) + fullpath := filepath.Join(homeDir, ".config/regex") + os.Setenv("REGEX_HOME", fullpath) } var data []byte var err error - cfgname := filepath.Join(os.Getenv("GEMINI_HOME"), "gemini.pb") + cfgname := filepath.Join(os.Getenv("REGEX_HOME"), "regex.pb") if data, err = loadFile(cfgname); err != nil { // something went wrong loading the file // all.sampleConfig() // causes nil panic return err } - // this means the gemini.pb file exists and was read + // this means the regex.pb file exists and was read if len(data) == 0 { // todo: add default data here since it's blank? // might cause nil panic? - all.AddGeminiComment("I like astronomy") - log.Info(errors.New("chatpb.ConfigLoad() gemini.pb is empty")) + all.AddRegexComment("I like astronomy") + log.Info(errors.New("chatpb.ConfigLoad() regex.pb is empty")) return nil } err = all.Unmarshal(data) @@ -149,7 +149,7 @@ func loadFile(fullname string) ([]byte, error) { data, err := os.ReadFile(fullname) if errors.Is(err, os.ErrNotExist) { // if file does not exist, just return nil. this - // will cause ConfigLoad() to try the next config file like "gemini.text" + // will cause ConfigLoad() to try the next config file like "regex.text" // because the user might want to edit the .config by hand return nil, nil } @@ -161,7 +161,7 @@ func loadFile(fullname string) ([]byte, error) { } func configWrite(filename string, data []byte) error { - fullname := filepath.Join(os.Getenv("GEMINI_HOME"), filename) + fullname := filepath.Join(os.Getenv("REGEX_HOME"), filename) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) defer cfgfile.Close() @@ -169,11 +169,11 @@ func configWrite(filename string, data []byte) error { log.Warn("open config file :", err) return err } - if filename == "gemini.text" { + if filename == "regex.text" { // add header - cfgfile.Write([]byte("# this file is automatically re-generated from gemini.pb, however,\n")) + cfgfile.Write([]byte("# this file is automatically re-generated from regex.pb, however,\n")) cfgfile.Write([]byte("# if you want to edit it by hand, you can:\n")) - cfgfile.Write([]byte("# stop gemini; remove gemini.pb; edit gemini.text; start gemini\n")) + cfgfile.Write([]byte("# stop regex; remove regex.pb; edit regex.text; start regex\n")) cfgfile.Write([]byte("# this will cause the default behavior to fallback to parsing this file for the config\n")) cfgfile.Write([]byte("\n")) cfgfile.Write([]byte("# this file is intended to be used to customize settings on what\n")) diff --git a/example.go b/example.go index 8c0ba38..e496463 100644 --- a/example.go +++ b/example.go @@ -7,10 +7,10 @@ import ( func ExampleChat() *Chats { conversation := NewChats() - conversation.AddGeminiComment("funny") + conversation.AddRegexComment("funny") /* - gchat := conversation.AddGeminiComment("funny") + gchat := conversation.AddRegexComment("funny") snip := new(CodeSnippet) snip.Filename = "log/snip1.txt" gchat.Snippets = append(gchat.Snippets, snip) @@ -18,7 +18,7 @@ func ExampleChat() *Chats { conversation.AddUserComment("yes") - conversation.AddGeminiComment("I like astronomy") + conversation.AddRegexComment("I like astronomy") dump := conversation.FormatTEXT() diff --git a/helpers.go b/helpers.go index 5c8a630..5385944 100644 --- a/helpers.go +++ b/helpers.go @@ -9,7 +9,7 @@ import ( "google.golang.org/protobuf/proto" ) -func (c *Chats) AddGeminiComment(s string) *ChatEntry { +func (c *Chats) AddRegexComment(s string) *ChatEntry { log.Info("FIX") return nil }