diff --git a/README.md b/README.md index e4e3d01a..e73e80aa 100644 --- a/README.md +++ b/README.md @@ -760,7 +760,7 @@ GLOBAL OPTIONS: --password value, -p value use specified token for updating Confluence page. Specify - as password to read password from stdin, or your Personal access token. Username is not mandatory if personal access token is provided. For more info please see: https://developer.atlassian.com/server/confluence/confluence-server-rest-api/#authentication. [$MARK_PASSWORD] --target-url value, -l value edit specified Confluence page. If -l is not specified, file should contain metadata (see above). [$MARK_TARGET_URL] --base-url value, -b value, --base_url value base URL for Confluence. Alternative option for base_url config field. [$MARK_BASE_URL] - --config value, -c value use the specified configuration file. (default: "~/.config/mark") [$MARK_CONFIG] + --config value, -c value use the specified configuration file. (default: System specific) [$MARK_CONFIG] --ci run on CI mode. It won't fail if files are not found. (default: false) [$MARK_CI] --space value use specified space key. If the space key is not specified, it must be set in the page metadata. [$MARK_SPACE] --parents value A list containing the parents of the document separated by parents-delimiter (default: '/'). These will be preprended to the ones defined in the document itself. [$MARK_PARENTS] @@ -772,7 +772,7 @@ GLOBAL OPTIONS: ``` You can store user credentials in the configuration file, which should be -located in ~/.config/mark (or specified via `-c --config `) with the following format (TOML): +located in a system specific directory (or specified via `-c --config `) with the following format (TOML): ```toml username = "your-email" @@ -785,6 +785,11 @@ drop-h1 = true **NOTE**: Labels aren't supported when using `minor-edit`! +**NOTE**: The system specific locations are described in here: +https://pkg.go.dev/os#UserConfigDir. +Currently these are: +On Unix systems, it returns $XDG_CONFIG_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.config. On Darwin, it returns $HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib. + # Tricks ## Continuous Integration diff --git a/main.go b/main.go index f6009eb4..8f8f7f13 100644 --- a/main.go +++ b/main.go @@ -132,7 +132,7 @@ var flags = []cli.Flag{ &cli.StringFlag{ Name: "config", Aliases: []string{"c"}, - Value: filepath.Join(os.Getenv("HOME"), ".config/mark"), + Value: configFilePath(), Usage: "use the specified configuration file.", TakesFile: true, EnvVars: []string{"MARK_CONFIG"}, @@ -189,11 +189,11 @@ func main() { return altsrc.NewTomlSourceFromFile(filePath) } else { // Fall back to default if config is unset and path exists - _, err := os.Stat(filepath.Join(os.Getenv("HOME"), ".config/mark")) + _, err := os.Stat(configFilePath()) if os.IsNotExist(err) { return &altsrc.MapInputSource{}, nil } - return altsrc.NewTomlSourceFromFile(filepath.Join(os.Getenv("HOME"), ".config/mark")) + return altsrc.NewTomlSourceFromFile(configFilePath()) } }), EnableBashCompletion: true, @@ -522,3 +522,11 @@ func processFile( return target } + +func configFilePath() string { + fp, err := os.UserConfigDir() + if err != nil { + log.Fatal(err) + } + return filepath.Join(fp, "mark") +}