Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XDG Base Directory #31

Closed
kevinschoon opened this issue Sep 6, 2020 · 3 comments
Closed

Support XDG Base Directory #31

kevinschoon opened this issue Sep 6, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@kevinschoon
Copy link
Owner

Pomo should support the XDG Base Directory specification and not default to polluting the home directory with ~/.pomo.

@kevinschoon kevinschoon added enhancement New feature or request help wanted Extra attention is needed labels Sep 6, 2020
@strogiyotec
Copy link
Contributor

Is it ok to support it using environmental variables in order to keep backward compatibility ?
As an example, postgres keeps history file in home directory and in order to change this behavior one should add this to .bashrc or .zshrc

export PSQL_HISTORY="$XDG_DATA_HOME/psql/history"

So in case of pomo it would be

export POMO_CONFIG="$XDG_CONFIG_HOME/pomo/pomo.json"
export POMO_DB="$XDG_DATA_HOME/pomo/pomo.db"

@kevinschoon
Copy link
Owner Author

Currently the default configuration for pomo looks like this:

{
  "colors": null,
  "dateTimeFmt": "2006-01-02 15:04",
  "basePath": "/home/kevin/.pomo",
  "dbPath": "/home/kevin/.pomo/pomo.db",
  "socketPath": "/home/kevin/.pomo/pomo.sock",
  "iconPath": "/home/kevin/.pomo/icon.png"
}

Where basePath includes the sqlite database, configuration, runtime socket, and supplemental files.
On Linux per the XDG spec, we should actually store the configuration with a structure like this:

# configuration is stored in
~/.config/pomo/config.json
# the database and supplemental files are in a shared directory
~/.local/share/pomo/pomo.db
~/.local/share/pomo/icon.png
# the runtime socket is stored in path like
/run/user/1000/pomo.socket

Regarding backward compatibility I'm fine with just adding some documentation instructing users to move their sqlite file into the new default path.

There is some relevant discussion in golang/go#29960 but I'm not entirely sure what the right solution is for non-linux systems.
Below is some example code that returns the correct default paths on Linux.

package main

import (
	"fmt"
	"os"
	"os/user"
	"path"
)

func getConfigPath() string {
	basepath, err := os.UserConfigDir()
	if err != nil {
		panic(err)
	}
	return path.Join(basepath, ".pomo/config.json")
}

func getDataDir() string {
	basepath := os.Getenv("XDG_DATA_HOME")
	if basepath == "" {
		user, _ := user.Current()
		return path.Join(user.HomeDir, ".local/share/pomo")
	}
	return path.Join(basepath, "pomo")
}

func getSocketPath() string {
	basepath := os.Getenv("XDG_RUNTIME_DIR")
	if basepath == "" {
		user, _ := user.Current()
		// BUG: What to do on OSX/Windows?
		return path.Join("/run/user", user.Uid, "pomo.socket")
	}
	return path.Join(basepath, "pomo.socket")
}

func main() {
	fmt.Println(getConfigPath())
	fmt.Println(getDataDir())
	fmt.Println(getSocketPath())
}
/home/kevin/.config/.pomo/config.json
/home/kevin/.local/share/pomo
/run/user/1000/pomo.socket

@kevinschoon
Copy link
Owner Author

Implemented with #58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants