Skip to content

Support $XDG_CONFIG_HOME in module search path#3464

Open
nsfisis wants to merge 2 commits intojqlang:masterfrom
nsfisis:feat/xdg-config-home
Open

Support $XDG_CONFIG_HOME in module search path#3464
nsfisis wants to merge 2 commits intojqlang:masterfrom
nsfisis:feat/xdg-config-home

Conversation

@nsfisis
Copy link

@nsfisis nsfisis commented Jan 18, 2026

Overview

Add support for the $XDG_CONFIG_HOME environment variable in module search path, following the XDG Base Directory Specification.

Related issue: #2966

Changes

Expand $JQ_CONFIG_HOME in module search path like $ORIGIN.

The actual value is resolved as follows:

  1. $XDG_CONFIG_HOME/jq if the environment variable $XDG_CONFIG_HOME is set and the directory exists
  2. Non-Windows platforms: $HOME/.config/jq if the directory exists
  3. $HOME/.jq

In addition, the default module search path is changed:

  • ~/.jq$JQ_CONFIG_HOME (changed)
  • $ORIGIN/../lib/jq
  • $ORIGIN/../lib

Original Changes

Note

This section describes the original changes before code review.

Expand $XDG_CONFIG_HOME/ in module search path to the value of the environment variable $XDG_CONFIG_HOME like $ORIGIN.

If $XDG_CONFIG_HOME is unset or empty,

  • Non-Windows: falls back to $HOME/.config, which is suggested by XDG Base Directory Specification
  • Windows: removes the path from search path list

In addition, add $XDG_CONFIG_HOME/jq to the default module search path. Search order is as follows:

  • ~/.jq
  • $XDG_CONFIG_HOME/jq (added)
  • $ORIGIN/../lib/jq
  • $ORIGIN/../lib

~/.jq takes priority over $XDG_CONFIG_HOME/jq to keep compatibility.

References

@nsfisis nsfisis force-pushed the feat/xdg-config-home branch from 132e432 to dabb7dd Compare January 18, 2026 12:58
@nsfisis nsfisis changed the title Support $XDG_CONFIG_HOME for default module search path Support $XDG_CONFIG_HOME in module search path Jan 18, 2026
@wader
Copy link
Member

wader commented Feb 7, 2026

I wonder if it would make more sense to skip search path changes and introduce a get_config_home function etc that do something like this:

  • if $XDG_CONFIG_HOME is set and is not empty use $XDG_CONFIG_HOME/jq
  • if $HOME/.config/jq exist and is a directory use it
  • use $HOME

and use it in load_program?

(note that i skipped thinking about windows here)

@nsfisis nsfisis marked this pull request as draft February 14, 2026 04:57
@nsfisis nsfisis force-pushed the feat/xdg-config-home branch from dabb7dd to 650a087 Compare February 14, 2026 10:25
@nsfisis nsfisis marked this pull request as ready for review February 14, 2026 10:39
@nsfisis
Copy link
Author

nsfisis commented Feb 14, 2026

Thank you for review!

I introduced $JQ_CONFIG_HOME, which is expanded to the resolved config home.

The value is determined as follows:

  1. $XDG_CONFIG_HOME/jq if the environment variable is set and the directory exists
  2. Non-Windows: $HOME/.config/jq if the directory exists
  3. $HOME/.jq (original jq config home)

If a user has $XDG_CONFIG_HOME/jq or ~/.config/jq, the scripts under the directories will be loaded. Otherwise, the ~/.jq directory is loaded as before.

@wader
Copy link
Member

wader commented Feb 19, 2026

Thanks. And i think it makes sense that this should not affect include "~/...", that would be confusing?

What do other maintainers thinks? it seems reasonable that jq should support XDG_CONFIG_HOME somehow

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.

2 participants