Skip to content

Conversation

@outtersg
Copy link

@outtersg outtersg commented Nov 3, 2025

This PR resolves #518: unable to use absolute paths in --ignore-files=

- ignore-files starting with a / are taken as absolute paths
- add a Path class to group all paths handling
add handling of tilde as a shortcut to $HOME in paths from options
@outtersg
Copy link
Author

outtersg commented Nov 4, 2025

This first iteration of this PR partly resolves #518 (on POSIX systems, so ironically not on @fatsen's system).

While it works for my use case this PR comes with 3 limitations:

  1. it hardcodes / to detect an absolute path; so, only works on POSIX and such. No Windows here, sorry.
  2. it does so by cloning Query::select()'s code
    And code duplication is bad.
  3. It doesn't expand the usual ~ shortcut, so for example my .ugrep needs to contain a full:
    ignore-files=/home/gui/.ugrep.ignore
    while it would be nice to have a simple (and relocatable):
    ignore-files=~/.ugrep.ignore

For these reasons, I consider this PR a first step towards a more general solution that would include a mutualized and robust Path class, 1. able to work on Windows, 2. used by both ugrep.cpp, ugrep-indexer.cpp, and query.cpp, and 3. detecting at least the ~ special pattern (mapped to getenv("HOME") on POSIX, and I don't know what on Windows).

… But as "Perfect is the enemy of good", this PR has the merit of being there.

recognize C:\-style paths as absolute on Windows
@outtersg outtersg force-pushed the absolute-ignore-files branch from 4821f4a to c8d859b Compare November 4, 2025 14:32
@outtersg
Copy link
Author

outtersg commented Nov 4, 2025

Now this should correctly handle ~, as well as @fatsen's Windows absolute paths, removing 2.5 of the 3 points in my previous comment (there's still 0.5 of code duplication, as I didn't plug it into query.cpp).

This uses a new Path class, with a single static from_dir() to handle those paths normalizations.

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.

use .ignore in $user directory

1 participant