w3m の urimethodmap
なんかこれ未だに undocumented な機能なんでしょうか。 ~/.w3m/urimethodmap に
ttp: h%s tp: ht%s
とか書いておくと 2ch で快適っていう機能です…というわけではなくたぶん isbn:// とかそういうのを適当に local CGI でほげほげするんでしょう。
まずこれの問題点は ttp://shinh.skr.jp/ にアクセスすると URI がそのスキームのまんまで、例えば外部ブラウザに渡す場合だとかにうまくいかんわけです。気持ち的には 302 Found とか的に処理して欲しいわけです。ていうわけで、
diff -u -r1.237 file.c --- file.c 4 Jan 2005 15:51:04 -0000 1.237 +++ file.c 20 Nov 2006 20:58:19 -0000 @@ -1762,10 +1762,14 @@ #ifdef USE_EXTERNAL_URI_LOADER tmp = searchURIMethods(&pu); if (tmp != NULL) { + tpath = path = tmp->ptr; + goto load_doc; +/* b = loadGeneralFile(tmp->ptr, current, referer, flag, request); if (b != NULL && b != NO_BUFFER) copyParsedURL(&b->currentURL, &pu); return b; +*/ } #endif /* FIXME: gettextize? */
で、 urimethodmap をハンドルする準備は整ったので、適当にスキームをでっちあげるCGIを書きました。
#!/usr/bin/env ruby require 'nkf' require 'cgi' def nkf(e, u) CGI.escape(NKF.nkf(e, CGI.unescape(u))) end begin M={ 'b'=>'"http://b.hatena.ne.jp/entrylist?url=#{u}"', 'a'=>'"http://web.archive.org/web/*/#{u}"', 'id'=>'"http://d.hatena.ne.jp/#{u}/"', 'g'=>'"http://www.google.co.jp/search?q=#{nkf("-w", u)}&lr=lang_ja"', 'we'=>'"http://en.wikipedia.org/wiki/#{nkf("-w", u)}"', 'wj'=>'"http://ja.wikipedia.org/wiki/#{nkf("-w", u)}"', } q=ENV['QUERY_STRING'] if q !~ /([a-z]+):\/?\/?(.*)/ puts %Q(Content-Type: text/html error: #{q}) end s=$1 u=$2 puts %Q(Status Code: 302 Found Location: #{eval(M[s])} ) rescue puts %Q(Content-Type: text/plain #{$!.backtrace.join("\n")}) end
最近新しいサイト知ったらこのサイト内のブックマーク状況どんな感じかなーて感じではてぶ使ったりするんですが、そんな時はURLの先頭に b: をつけるだけ、同じく archive.org は a: つけるだけ、とかまぁそんな感じです。あと g:hoge で検索とか id: 表記とか we: と wj: で Wikipedia とか。
あ、あと ~/.w3m/urimethodmap は
ttp: h%s tp: ht%s a: http://localhost/~i/urimethodmap.cgi?%s g: http://localhost/~i/urimethodmap.cgi?%s b: http://localhost/~i/urimethodmap.cgi?%s id: http://localhost/~i/urimethodmap.cgi?%s we: http://localhost/~i/urimethodmap.cgi?%s wj: http://localhost/~i/urimethodmap.cgi?%s
って感じ。パスは適当に。