Skip to content

Instantly share code, notes, and snippets.

@audreyt
Last active October 2, 2016 17:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audreyt/4648550 to your computer and use it in GitHub Desktop.
Save audreyt/4648550 to your computer and use it in GitHub Desktop.
簡單的 ~/bin/moe 命令列搜尋器。
#!/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;
];
}
@audreyt
Copy link
Author

audreyt commented Jan 27, 2013

後綴 $ 表示單詞比對(而非預設的前綴比對):

$ moe 萌$
萌  ㄇㄥˊ
» 草木初生的芽。說文解字:「萌,艸芽也。」唐˙韓愈、劉師服、侯喜、軒轅彌明˙石鼎聯句:「秋瓜未落蒂,凍芋
  強抽萌。」
» 事物發生的開端或徵兆。韓非子˙說林上:「聖人見微以知萌,見端以知末。」漢˙蔡邕˙對詔問灾異八事:「以
  杜漸防萌,則其救也。」
» 人民。通「氓」。如:「萌黎」、「萌隸」。
» 姓。如五代時蜀有萌慮。
» 發芽。如:「萌芽」。楚辭˙王逸˙九思˙傷時:「明風習習兮龢暖,百草萌兮華榮。」
» 發生。如:「故態復萌」。管子˙牧民:「惟有道者,能備患於未形也,故禍不萌。」三國演義˙第一回:「若
  萌異心,必獲惡報。」

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment