Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Attempt to read a global system configuration file if `~/.config/privatebin/config.json` is not found. On Windows, `C:\ProgramData\privatebin\config.json` and on other operating systems, `/etc/privatebin/config.json`.

## [2.1.1] - 2025-09-08

### Fixed
Expand Down
19 changes: 18 additions & 1 deletion cmd/privatebin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -83,6 +84,22 @@ var (
}

cfgPath = path.Join(homeDir, ".config", "privatebin", "config.json")

// Try to load from user's config first
_, err = os.Stat(cfgPath)
if err != nil {
// If user config doesn't exist, try system-wide config
var systemPath string
if runtime.GOOS == "windows" {
systemPath = path.Join("C:", "ProgramData", "privatebin", "config.json")
} else {
systemPath = path.Join(string(os.PathSeparator), "etc", "privatebin", "config.json")
}

if _, err := os.Stat(systemPath); err == nil {
cfgPath = systemPath
}
}
}

cfg, err := loadCfgFile(cfgPath)
Expand Down Expand Up @@ -303,7 +320,7 @@ var (

func init() {
rootCmd.PersistentFlags().StringVarP(&output, "output", "o", "", "the command output format")
rootCmd.PersistentFlags().StringVarP(&cfgPath, "config", "c", "", "the config file (default is $HOME/.config/privatebin/config.json)")
rootCmd.PersistentFlags().StringVarP(&cfgPath, "config", "c", "", "the config file (default is $HOME/.config/privatebin/config.json, or system-wide /etc/privatebin/config.json on Linux/macOS, C:\\ProgramData\\privatebin\\config.json on Windows)")
rootCmd.PersistentFlags().StringVarP(&binName, "bin", "b", "", "the name of the privatebin instance to use (default \"\")")
rootCmd.PersistentFlags().StringSliceVarP(&extraHeaderFields, "header", "H", []string{}, "extra HTTP header fields to include in the request sent")

Expand Down
2 changes: 2 additions & 0 deletions doc/privatebin.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ instances.
**-c, -\-config** \<path\>
: The path of the configuration file (default
"~/.config/privatebin/config.json").
If not found, the CLI will also look for a system-wide configuration file at
"/etc/privatebin/config.json" (Linux/macOS) or "C:\\ProgramData\\privatebin\\config.json" (Windows).

**-H, -\-header** \<key=value\>
: The extra HTTP header fields to include in the request sent.
Expand Down
9 changes: 7 additions & 2 deletions doc/privatebin.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ A bit more complete configuration file:
# FILES

_~/.config/privatebin/config.json_
: Default location of the privatebin configuration. The file has to be
created manually as it is not installed with a standard installation.
: Default location of the privatebin configuration. The file has to be created manually as it is not installed with a standard installation.

_/etc/privatebin/config.json_ (Linux/macOS)
: System-wide configuration file location, used if the user config is not found.

_C:\\ProgramData\\privatebin\\config.json_ (Windows)
: System-wide configuration file location, used if the user config is not found.

# AUTHORS

Expand Down