diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml index f2000f6ffa..6023a51716 100644 --- a/docs/content/manual/manual.yml +++ b/docs/content/manual/manual.yml @@ -3662,7 +3662,7 @@ sections: For example, with `-L$HOME/.jq` a module `foo` can be found in `$HOME/.jq/foo.jq` and `$HOME/.jq/foo/foo.jq`. - If `$HOME/.jq` is a file, it is sourced into the main program. + If `~/.jq` is a file, it is sourced into the main program. entries: - title: "`import RelativePathString as NAME [];`" diff --git a/jq.1.prebuilt b/jq.1.prebuilt index efa5aa2f34..a5447e83ff 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -4084,7 +4084,7 @@ Consecutive components with the same name are not allowed to avoid ambiguities ( For example, with \fB\-L$HOME/\.jq\fR a module \fBfoo\fR can be found in \fB$HOME/\.jq/foo\.jq\fR and \fB$HOME/\.jq/foo/foo\.jq\fR\. . .P -If \fB$HOME/\.jq\fR is a file, it is sourced into the main program\. +If \fB~/\.jq\fR is a file, it is sourced into the main program\. . .SS "import RelativePathString as NAME [];" Imports a module found at the given path relative to a directory in a search path\. A \fB\.jq\fR suffix will be added to the relative path string\. The module\'s symbols are prefixed with \fBNAME::\fR\. diff --git a/src/linker.c b/src/linker.c index e7d1024c1d..2439babc92 100644 --- a/src/linker.c +++ b/src/linker.c @@ -420,13 +420,13 @@ int load_program(jq_state *jq, struct locfile* src, block *out_block) { return 1; } - char* home = getenv("HOME"); - if (home) { // silently ignore no $HOME - /* Import ~/.jq as a library named "" found in $HOME */ + jv home = get_home(); + if (jv_is_valid(home)) { // silently ignore if home dir not determined + /* Import ~/.jq as a library named "" found in $HOME or %USERPROFILE% */ block import = gen_import_meta(gen_import("", NULL, 0), gen_const(JV_OBJECT( jv_string("optional"), jv_true(), - jv_string("search"), jv_string(home)))); + jv_string("search"), home))); program = BLOCK(import, program); }