Explorar el Código

Hack together a firefox history search...

Luna Stadler %!s(int64=4) %!d(string=hace) años
padre
commit
9729e56c6f
Se han modificado 1 ficheros con 23 adiciones y 0 borrados
  1. 23 0
      zig/sdl/hello_sdl.zig

+ 23 - 0
zig/sdl/hello_sdl.zig

@ -384,6 +384,28 @@ const FileRunner = struct {
384 384
    }
385 385
};
386 386
387
const FirefoxHistoryRunner = struct {
388
    fn init() Runner {
389
        return Runner{ .name = "ff", .run_always = true, .toArgv = toArgv, .isActive = isActive };
390
    }
391
392
    fn isActive(cmd: []const u8) bool {
393
        return cmd.len > "ff ".len and std.mem.startsWith(u8, cmd, "ff ");
394
    }
395
396
    fn toArgv(cmd: []const u8) []const []const u8 {
397
        // FIXME: replace with choice + selection whenever that is implemented
398
        const cmd_fmt =
399
            \\find ~/.mozilla -type f -name 'places.sqlite' -exec bash -c 'cp {{}} /tmp && sqlite3 /tmp/places.sqlite "select title, url from moz_places where url like \"%{s}%\" or url like \"%{s}%\" order by last_visit_date desc limit 100;" | tee /tmp/places-result; [ "$(wc -l < /tmp/places-result)" = "1" ] && xdg-open $(head -n1 /tmp/places-result | cut -d\| -f2) && test -f /usr/bin/swaymsg && swaymsg '[app_id="firefox"]' focus &> /dev/null; rm /tmp/places.sqlite;' \;
400
        ++ "\x00";
401
402
        _ = std.fmt.bufPrint(&cmd_buf, cmd_fmt, .{ cmd["ff ".len..], cmd["ff ".len..] }) catch "???";
403
        return &[_][]const u8{ "bash", "-c", &cmd_buf };
404
    }
405
};
406
407
// TODO: window switcher (do i even want that?)
408
387 409
const LogsRunner = struct {
388 410
    fn init() Runner {
389 411
        return Runner{ .name = "logs", .run_always = true, .toArgv = toArgv, .isActive = isActive };
@ -560,6 +582,7 @@ pub fn main() !void {
560 582
        ManPageRunner.init(),
561 583
        SearchRunner.init(),
562 584
        FileRunner.init(),
585
        FirefoxHistoryRunner.init(),
563 586
        LogsRunner.init(),
564 587
        QalcRunner.init(),
565 588
        SelfDocRunner.init(),