📄 fquote.vtc
字号:
if (!depend_loaded) Load("depend");register_file("fquote");func prog_output(cmd) [fp, line, list] { fp = popen(cmd, "r"); list = new_list(); while (line = fread(fp)) add_list(list, line); fclose(fp); return list;}func file_line(name, num) { return prog_output(bprintf("sed -n %dp %s", num, name))[1];}func lines_in_file(name) { return atoi(skipspaces(prog_output("wc -l " + name)[1]));}func rand(n) --> (n < 256) ? (rnd >> 7) % n : rnd % nfunc new_sequence(n) [seq] { seq = alloc(n + 1); *seq = n; return seq; }func sequence_elem(seq) [n, p] { if (!*seq) return -1; for (n = rand((*seq)--); *++seq || n--;); *seq = 1; return seq - base(seq);}Tquoter ?:= new_assoc();&Tquoter->name; &Tquoter->seq;func new_quoter(name) { return ptable(Tquoter, name, new_sequence(lines_in_file(name)));}func get_quote(quoter) [n] { n = sequence_elem(quoter->seq); if (n == -1) { quoter->seq = new_sequence(lines_in_file(quoter->name)); if (!*quoter->seq) return NULL; return get_quote(quoter); } return file_line(quoter->name, n);}func sh_quote(s) [r, p] { r = "'"; while (p = strchr(s, '\'')) { strcat(r, s, p - s); strcat(r, "'\\''"); s = p + 1; } strcat(r, s); strcat(r, "'"); return r;}func get_quote_matching(quoter, regstr) [l, copy, n] { l = prog_output("grep -h -n " + sh_quote(regstr) + " " + quoter->name); if (!*l) return NULL; copy = adup(*l + 1, l); while (*l) { n = rand(*l) + 1; if (!quoter->seq[atoi(l[n])]) { quoter->seq[atoi(l[n])] = 1; (*quoter->seq)--; return strchr(l[n], ':') + 1; } del_list(l, n); } return strchr(copy[rand(*copy) + 1], ':') + 1;}thequotefile = getenv("HOME") + "/.vtquotes";[fp] if (fsize(thequotefile) == -1) { fp = fopen(thequotefile, "w"); fclose(fp);}thequoter = new_quoter(thequotefile);func Fquote(s) [line] { line = *s ? get_quote_matching(thequoter, s) : get_quote(thequoter); if (line) sendf(":| %s", line); else output("Could not obtain quote.\n");}func Addquote(s) [fp] { fp = fopen(thequotefile, "a"); fwrite(fp, s + "\n"); fclose(fp);}add_cmd("fquote", -1, .Fquote, "/fquote");add_cmd("addquote", -1, .Addquote, "/addquote <line>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -