-
-
Save norcalli/73db7da40f9ee4db9c26f0ffb00fae4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# requires git lua lua-cjson lua-redis redis redis-cli | |
set -eo pipefail | |
REDIS_KEY=dictionary | |
test $(redis-cli exists $REDIS_KEY) = 1 || { | |
curl -L static.kiani.io/WebstersEnglishDictionary.txt.gzip \ | |
| gzip -d \ | |
| tr -d $"\r" \ | |
| awk '/^$/ { lastempty = 1; next } start == 1 { lastempty = 0; print "|" $0; start += 1; next } lastempty && /^([-_A-Z 0-9]+)(; *([-_A-Z 0-9]+))*$/{ print $0; start = 1; lastempty = 0; next }; start { lastempty = 0; print "|"$0 }' \ | |
| lua -e ' | |
C={}; | |
c = require("redis").connect(); | |
function add(k,d) | |
if k and d then | |
for x in k:gmatch("[^;]+") do | |
C[x] = C[x] or {} | |
table.insert(C[x], d) | |
end | |
end | |
end | |
for l in io.lines() do | |
if not l:match("^|") then | |
add(k,d) | |
d = "" | |
k = l | |
else | |
d = d .. "\n" .. l:sub(2) | |
end | |
end | |
add(k,d) | |
for k,data in pairs(C) do | |
for i, v in ipairs(data) do | |
local x = k | |
if #data > 1 then | |
x = ("%s[%d]"):format(k, i) | |
end | |
c:hset("'$REDIS_KEY'", x:gsub("^%s+", ""):gsub("%s+$", ""):lower(), v) | |
end | |
end | |
' | |
} | |
# --bind 'enter:execute-silent(wl-copy {})+abort,ctrl-y:execute-silent(wl-copy {}),pgdn:preview-down,pgup:preview-up' \ | |
redis-cli hkeys $REDIS_KEY | sort -dV | fzf \ | |
--tiebreak=begin \ | |
--bind 'enter:execute-silent(wl-copy {})+beginning-of-line+kill-line,ctrl-y:execute-silent(wl-copy {})' \ | |
--preview-window down:75%:wrap \ | |
--preview "redis-cli hget $REDIS_KEY {}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment