Skip to content

feat: add XDG Base Directory support for config files - #560

Open
EliteCracker wants to merge 1 commit into
dvorka:masterfrom
EliteCracker:xdg-compliance
Open

EliteCracker wants to merge 1 commit into
dvorka:masterfrom
EliteCracker:xdg-compliance

Conversation

@EliteCracker

Copy link
Copy Markdown

Description

Adds support for the XDG Base Directory specification.

Changes

  • Configuration files (blacklist, favorites) now default to $XDG_CONFIG_HOME/hstr/ (usually ~/.config/hstr/).
  • Maintains backward compatibility: if ~/.hstr_favorites or ~/.hstr_blacklist exist, they are used instead of XDG paths.
  • Automatically creates the configuration directory structure if it doesn't exist.

Testing

Verified in a clean Arch Linux chroot:

  • Detected legacy files when present.
  • Created ~/.config/hstr/ when no legacy files existed.
  • Respected custom XDG_CONFIG_HOME environment variable.

Disclaimer

I did use Google Gemini 3 for assistance during this. I noticed this program had an old issue (#461), and I highly prefer a minimal $HOME. Therefore, I used the Arch Wiki to implement Gemini's changes, tested those changes, and here we are.

- Implemented get_hstr_configuration_file_path in hstr_utils to handle XDG resolution.
- Updated blacklist and favorites to use XDG_CONFIG_HOME/hstr/ or ~/.config/hstr/.
- Added legacy fallback to ~/.hstr_favorites and ~/.hstr_blacklist.
- Ensure config directories are created automatically.
@dvorka dvorka added this to the HSTR 3.x milestone Sep 23, 2026
@dvorka
dvorka requested review from dvorka and a lite review from Copilot September 23, 2026 06:45
@dvorka dvorka self-assigned this Sep 23, 2026
@dvorka dvorka modified the milestones: HSTR 3.x, HSTR 3.3 Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Resolve filename, write-error, relative-path, and documentation issues before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity

Open (3)
What changed in this PR

Adds XDG Base Directory support for favorites and blacklist files while preserving legacy-file precedence.

Changes:

  • Adds centralized XDG path resolution and directory creation.
  • Updates favorites and blacklist persistence.
  • Adds filesystem support declarations.
File Description
src/​include/​hstr_utils.h Declares XDG configuration support.
src/​hstr_utils.c Resolves and creates configuration paths.
src/​hstr_favorites.c Uses XDG-aware favorites persistence.
src/​hstr_blacklist.c Uses XDG-aware blacklist persistence.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hstr_blacklist.c
if(!fwrite(keys[i], sizeof(char), strlen(keys[i]), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
if (outputFile) {
Comment thread src/hstr_favorites.c
if(!fwrite(favorites->items[i], sizeof(char), strlen(favorites->items[i]), outputFile)) {
if(ferror(outputFile)) {
exit(EXIT_FAILURE);
if (outputFile) {
Comment thread src/hstr_utils.c
Comment on lines +234 to +236
if (xdg_config_home_env && strlen(xdg_config_home_env) > 0) {
xdg_path_dir = malloc(strlen(xdg_config_home_env) + 1 + strlen("hstr") + 1);
sprintf(xdg_path_dir, "%s/hstr", xdg_config_home_env);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants