Last active
October 2, 2016 17:03
-
-
Save audreyt/4648550 to your computer and use it in GitHub Desktop.
簡單的 ~/bin/moe 命令列搜尋器。
This file contains hidden or 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
#!/usr/bin/env perl | |
use constant MoeDatabase => "$ENV{HOME}/w/newdict/development.sqlite3"; | |
for my $arg (@ARGV) { | |
my $col = 'title'; | |
if ($arg =~ /%$/) { | |
$arg = "%$arg"; | |
$col = 'def'; | |
} | |
$arg .= '%' unless $arg =~ s/\$$//; | |
system sqlite3 => MoeDatabase, qq[ | |
SELECT '' || title || '\t' || heteronyms.bopomofo || '\n» ' || group_concat( | |
def, '\n» ' | |
) || '\n' | |
FROM entries | |
JOIN heteronyms ON entry_id = entries.id | |
JOIN definitions ON heteronym_id = heteronyms.id | |
WHERE $col LIKE '$arg' | |
GROUP BY title, heteronyms.bopomofo; | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
後綴 $ 表示單詞比對(而非預設的前綴比對):