Skip to content

Commit 98d50b8

Browse files
chore: change the location of gbc.conf file
1 parent ddfa594 commit 98d50b8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

cmd/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
"github.com/allancapistrano/gbc/config"
1717
)
1818

19-
const GBCVERSION = "1.0.0"
19+
const GBC_VERSION = "1.0.0"
20+
const SETTINGS_FILE_NAME = "gbc.conf"
2021

2122
// rootCmd represents the base command when called without any subcommands
2223
var rootCmd = &cobra.Command{
@@ -29,11 +30,11 @@ simple way to write commits following the Conventional Commits
2930

3031
fstatus, _ := cmd.Flags().GetBool("version")
3132
if fstatus {
32-
fmt.Printf("gbc version %s\n", GBCVERSION)
33+
fmt.Printf("gbc version %s\n", GBC_VERSION)
3334
} else {
3435
commitTypeMenu := gocliselect.NewMenu("Commit type?")
35-
gbcEmojis := config.GetEmojis("config/gbc.conf", false)
36-
enableEmojis := config.EnableEmojis("config/gbc.conf", false)
36+
gbcEmojis := config.GetEmojis(SETTINGS_FILE_NAME, true)
37+
enableEmojis := config.EnableEmojis(SETTINGS_FILE_NAME, true)
3738

3839
commitTypeMenu.AddItem(
3940
emoji.Sprintf("%sFeature", gbcEmojis.Feat),

config/settings.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"os"
11+
"path/filepath"
1112
"strconv"
1213
"strings"
1314
)
@@ -27,7 +28,16 @@ type Emoji struct {
2728

2829
func GetEmojis(fileName string, debug bool) Emoji {
2930
foundSettingsFile := true
30-
file, err := os.Open(fileName)
31+
homeDir, err := os.UserHomeDir()
32+
if err != nil {
33+
if debug {
34+
fmt.Println("Couldn't open the user home directory.")
35+
}
36+
foundSettingsFile = false
37+
}
38+
39+
filePath := filepath.Join(homeDir, ".config", "gbc", fileName)
40+
file, err := os.Open(filePath)
3141
if err != nil {
3242
if debug {
3343
fmt.Printf(
@@ -106,7 +116,16 @@ func GetEmojis(fileName string, debug bool) Emoji {
106116

107117
func EnableEmojis(fileName string, debug bool) bool {
108118
foundSettingsFile := true
109-
file, err := os.Open(fileName)
119+
homeDir, err := os.UserHomeDir()
120+
if err != nil {
121+
if debug {
122+
fmt.Println("Couldn't open the user home directory.")
123+
}
124+
foundSettingsFile = false
125+
}
126+
127+
filePath := filepath.Join(homeDir, ".config", "gbc", fileName)
128+
file, err := os.Open(filePath)
110129
if err != nil {
111130
if debug {
112131
fmt.Printf(

0 commit comments

Comments
 (0)