dates mask in -g #2989
-
Is there any way to mask the current year, month, week, day in -g? $ rg -N --sort path '^(#+\s+)' -g '2025-02-{10,11,12,13,14}.md' -r ' ' but need something like $ rg -N --sort path '^(#+\s+)' -g '{YYYY}-{MM}-??.md' -r ' ' or even better to enumerate days of the current week... I know that some tricks possible on Linux, but on Windows it sounds like a pain and overscripting like this $days = @()
$monday = (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays(-(Get-Date).DayOfWeek.value__ + 1)
$date = [DateTime] $monday
while ($date -le (Get-Date)) {
if ($date.ToString('yyyy-MM') -eq (Get-Date).ToString('yyyy-MM'))
{
$days += $date.ToString('yyyy-MM-dd')
}
$date = $date.AddDays(1)
}
$days = [system.String]::Join(",", $days)
. rg -N --sort path '^(#+\s+)' -g "{$days}.md" -r ' ' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The On Unix, I would do something like this: I don't know if Windows has an equivalent to If you need a portable program to emit dates, you can consider using Jiff in a Rust program. Drop this in a directory in a file named use jiff::{civil::Weekday, ToSpan, Zoned};
fn main() -> anyhow::Result<()> {
let monday = Zoned::now().tomorrow()?.nth_weekday(-1, Weekday::Monday)?;
let weekdays = monday.date().series(1.day());
let strings: Vec<String> = weekdays.map(|date| date.to_string()).collect();
println!("{}", strings.join(","));
Ok(())
} (You might want to tweak how the starting Monday is found, depending on how you want to handle weekends. The above will always find the previous Monday, unless the current day is Monday.) And this in the same directory named [package]
publish = false
name = "jiff-days-of-week"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.95"
jiff = "0.2.0"
[[bin]]
name = "jiff-days-of-week"
path = "main.rs" Then run it:
Or build it into a binary:
That should work fine on Windows, macOS or Linux. |
Beta Was this translation helpful? Give feedback.
The
-g/--glob
flag just accepts a glob. I don't see why it should have knowledge about datetimes.On Unix, I would do something like this:
rg --files | rg '[0-9]{4}-[0-9]{2}-(10|11|12|13|14).md' | xargs rg -N --sort path '^(#+\s+)' -r ' '
. If your file paths have spaces in them, you'd need some-0
and--null-data
flags in there too I imagine.I don't know if Windows has an equivalent to
xargs
, but it's insanely useful for this sort of thing.If you need a portable program to emit dates, you can consider using Jiff in a Rust program. Drop this in a directory in a file named
main.rs
: