VIM slovník a tezaurus
27. 11. 2019 #kód
.vimrc
function! s:RunShellCommand(cmdline) let expanded_cmdline = a:cmdline for part in split(a:cmdline, ' ') if part[0] =~ '\v[%#<]' let expanded_part = fnameescape(expand(part)) let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '') endif endfor botright new resize 10 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile execute '$read !'. expanded_cmdline 1 normal dd setlocal nomodifiable endfunction command! -nargs=1 Thes call s:RunShellCommand("~/bin/thes ".<q-args>) command! -nargs=1 Dict call s:RunShellCommand("~/bin/dictlist ".<q-args>) nmap KT :Thes <C-R><C-W><cr> nmap KD :Dict <C-R><C-W><cr>
dictlist
#!/usr/bin/env bash dict -f "$@" | grep -vF dicts.info | tail -n+2 | grep -vP '/.+/' | sed -e 's/^\s\+//' | grep --color=never .
thes.d
import std.stdio; import std.range; import std.string; import std.regex; int main(string[] args) { if (args.length < 2) return 0; auto term = args[1]; if (term.length == 0) return 0; auto file = "/usr/share/mythes/th_cs_CZ_v2.dat"; auto r = regex(`\(.+?\)`); auto output = false; auto thesLinesCount = 0; foreach (l; File(file).byLineCopy) { if (l[0] != '|' && l[0] != '(') { if (output) writeln(); output = l.indexOf(term) >= 0; thesLinesCount = 0; if (output) { auto end = l.indexOf('|'); end = (end < 0 ? l.length : end); write("*** " ~ l[0..end] ~ " *** "); } } else { if (output) { if (thesLinesCount++ > 0) { write(", "); } write(replaceAll(l, r, "").drop(1).replace("|", ", ")); } } } return 0; }