jake-stewart / jfind

MIT License
54 stars 6 forks source link

python scripting #21

Open jake-stewart opened 1 year ago

jake-stewart commented 1 year ago

the script should be the final argument to jfind

for e.g:

ps aux | tail +2 | jfind 'interval(1, refresh)'

this would allow for easier customisation. for example there could be a lua function which highlights a line in the preview. this would make live grep work without the nasty --preview-line flag.

jfind '
    command("rg -n")

    map(ctrl_r, refresh)

    onItemChange(function(item)
        file, line = item:match("(.*):(.*):")
        preview("cat", file)
        highlightPreviewLine(line)
    end)'

and then while doing live grep you could enter fuzzy matching mode with the grepped results

jfind '
    local cmd = "rg -n"
    command(cmd)

    map(ctrl_r, refresh)

    onItemChange(function(item)
        file, line = item:match("(.*):(.*):")
        preview("cat", file)
        highlightPreviewLine(line)
    end)

    local fuzzyMode = false
    map(ctrl_f, function()
        if fuzzyMode then
            useMatcher(FUZZY)
        else
            command(cmd)
        end
        fuzzyMode = ~fuzzyMode
    end)'
WingDust commented 1 year ago

Lua is not a good choice for handling UTF8 characters like

print (string.sub("s你好-test", 1, 3)) characters are truncated,

and Jfind spends most of the time doing string processing

jake-stewart commented 1 year ago

Lua is not a good choice for handling UTF8 characters like

print (string.sub("s你好-test", 1, 3)) characters are truncated,

and Jfind spends most of the time doing string processing

we can provide our own string.sub and other utils. unless you have other ideas?

i dislike many languages, lua very much included

WingDust commented 1 year ago

pybind11 is recommended Because head-only is easy to compile

  1. Python is a widely used scripting language

  2. Packages that process text can be added directly

jake-stewart commented 1 year ago

pybind11 is recommended Because head-only is easy to compile

  1. Python is a widely used scripting language
  2. Packages that process text can be added directly

i love it