diff --git a/README.md b/README.md index eef192e..5789e76 100644 --- a/README.md +++ b/README.md @@ -378,11 +378,11 @@ To use standard colorschemes, clone the [colors](https://github.com/cointop-sh/c ```bash -$ cd ~/.cointop +$ cd ~/.config/cointop $ git clone git@github.com:cointop-sh/colors.git ``` -Then edit your config `~/.cointop/config.toml` and set the colorscheme you want to use: +Then edit your config `~/.config/cointop/config.toml` and set the colorscheme you want to use: ```toml colorscheme = "" @@ -409,12 +409,12 @@ To create your own colorscheme; simply copy an existing [colorscheme](https://gi The first time you run cointop, it'll create a config file in: ``` -~/.cointop/config.toml +~/.config/cointop/config.toml ``` You can then configure the actions you want for each key: -(default `~/.cointop/config.toml`) +(default `~/.config/cointop/config.toml`) ```toml currency = "USD" @@ -610,11 +610,13 @@ Frequently asked questions: - Q: How do I create a custom colorscheme? - - A: Copy an existing [colorscheme](https://github.com/cointop-sh/colors/blob/master/cointop.toml) to `~/.cointop/colors/` and customize the colors. Then run cointop with `--colorscheme ` to use the colorscheme. + - A: Copy an existing [colorscheme](https://github.com/cointop-sh/colors/blob/master/cointop.toml) to `~/.config/cointop/colors/` and customize the colors. Then run cointop with `--colorscheme ` to use the colorscheme. - Q: Where is the config file located? - - A: The default configuration file is located under `~/.cointop/config.toml` + - A: The default configuration file is located under `~/.config/cointop/config.toml` + + Note: Previous version of cointop used `~/.cointop/config` or `~/.cointop/config.toml` as the default config filepath. Cointop will use those config filepaths respectively if they exist. - Q: What format is the configuration file in? diff --git a/cmd/cointop.go b/cmd/cointop.go index 7158931..58a8b73 100644 --- a/cmd/cointop.go +++ b/cmd/cointop.go @@ -1,6 +1,8 @@ package cmd import ( + "fmt" + "github.com/miguelmota/cointop/cointop" "github.com/spf13/cobra" ) @@ -84,10 +86,10 @@ For more information, visit: https://github.com/miguelmota/cointop`, rootCmd.Flags().BoolVarP(&hideStatusbar, "hide-statusbar", "", false, "Hide the bottom statusbar") rootCmd.Flags().BoolVarP(&onlyTable, "only-table", "", false, "Show only the table. Hides the chart and top and bottom bars") rootCmd.Flags().UintVarP(&refreshRate, "refresh-rate", "r", 60, "Refresh rate in seconds. Set to 0 to not auto-refresh") - rootCmd.Flags().StringVarP(&config, "config", "c", "", "Config filepath. (default ~/.cointop/config.toml)") + rootCmd.Flags().StringVarP(&config, "config", "c", "", fmt.Sprintf("Config filepath. (default %s)", cointop.DefaultConfigFilepath)) rootCmd.Flags().StringVarP(&cmcAPIKey, "coinmarketcap-api-key", "", "", "Set the CoinMarketCap API key") rootCmd.Flags().StringVarP(&apiChoice, "api", "", cointop.CoinGecko, "API choice. Available choices are \"coinmarketcap\" and \"coingecko\"") - rootCmd.Flags().StringVarP(&colorscheme, "colorscheme", "", "", "Colorscheme to use (default \"cointop\"). To install standard themes, do:\n\ngit clone git@github.com:cointop-sh/colors.git ~/.cointop/colors\n\nFor additional instructions, visit: https://github.com/cointop-sh/colors") + rootCmd.Flags().StringVarP(&colorscheme, "colorscheme", "", "", "Colorscheme to use (default \"cointop\"). To install standard themes, do:\n\ngit clone git@github.com:cointop-sh/colors.git ~/.config/cointop/colors\n\nFor additional instructions, visit: https://github.com/cointop-sh/colors") var versionCmd = &cobra.Command{ Use: "version", diff --git a/cointop/cointop.go b/cointop/cointop.go index bff0ab8..9621799 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "strings" "sync" "time" @@ -138,15 +137,8 @@ type APIKeys struct { cmc string } -var defaultColorscheme = "cointop" - -func defaultConfigPath() (string, error) { - dir, err := os.UserConfigDir() - if err != nil { - return "", err - } - return filepath.Join(dir, "cointop", "config.toml"), nil -} +var DefaultColorscheme = "cointop" +var DefaultConfigFilepath = "~/.config/cointop/config.toml" // NewCointop initializes cointop func NewCointop(config *Config) (*Cointop, error) { @@ -155,16 +147,7 @@ func NewCointop(config *Config) (*Cointop, error) { debug = true } - configFilepath, err := defaultConfigPath() - if err != nil { - return nil, err - } - - if config != nil { - if config.ConfigFilepath != "" { - configFilepath = config.ConfigFilepath - } - } + configFilepath := DefaultConfigFilepath ct := &Cointop{ apiChoice: CoinGecko, @@ -214,7 +197,7 @@ func NewCointop(config *Config) (*Cointop, error) { }, } - err = ct.setupConfig() + err := ct.setupConfig() if err != nil { return nil, err } diff --git a/cointop/config.go b/cointop/config.go index f7495f4..54c73b6 100644 --- a/cointop/config.go +++ b/cointop/config.go @@ -67,20 +67,26 @@ func (ct *Cointop) setupConfig() error { func (ct *Cointop) createConfigIfNotExists() error { ct.debuglog("createConfigIfNotExists()") + + // NOTE: this is to support previous default config filepaths + previousDefaultConfigPaths := []string{ + "~/.cointop/config", + "~/.cointop/config.toml", + } + + for _, previousConfigFilepath := range previousDefaultConfigPaths { + normalizedPath := NormalizePath(previousConfigFilepath) + if _, err := os.Stat(normalizedPath); err == nil { + ct.configFilepath = normalizedPath + return nil + } + } + err := ct.makeConfigDir() if err != nil { return err } - // NOTE: legacy support for default path - path := ct.configPath() - oldConfigPath := NormalizePath(strings.Replace(path, "cointop/config.toml", "cointop/config", 1)) - if _, err := os.Stat(oldConfigPath); err == nil { - path = oldConfigPath - ct.configFilepath = oldConfigPath - return nil - } - err = ct.makeConfigFile() if err != nil { return err @@ -304,7 +310,7 @@ func (ct *Cointop) getColorschemeColors() (map[string]interface{}, error) { ct.debuglog("getColorschemeColors()") var colors map[string]interface{} if ct.colorschemeName == "" { - ct.colorschemeName = defaultColorscheme + ct.colorschemeName = DefaultColorscheme if _, err := toml.Decode(DefaultColors, &colors); err != nil { return nil, err } @@ -320,7 +326,7 @@ func (ct *Cointop) getColorschemeColors() (map[string]interface{}, error) { return colors, nil } - return nil, fmt.Errorf("The colorscheme file %q was not found.\n\nTo install standard themes, do:\n\ngit clone git@github.com:cointop-sh/colors.git ~/.cointop/colors\n\nFor additional instructions, visit: https://github.com/cointop-sh/colors", path) + return nil, fmt.Errorf("The colorscheme file %q was not found.\n\nTo install standard themes, do:\n\ngit clone git@github.com:cointop-sh/colors.git ~/.config/cointop/colors\n\nFor additional instructions, visit: https://github.com/cointop-sh/colors", path) } if _, err := toml.DecodeFile(path, &colors); err != nil {