Today's activity: Wrote a text-to-html converter for logs of chat.vim-users.jp

2009-05-30T19:49:32 / vim, ruby, prog / comment

Today I wrote chat.vim-users.jp-log-converter, a text-to-html converter for logs of chat.vim-users.jp (sample output). I wrote it as a Ruby script, but it's a bit hard for me. Because I almost forgot how to program with Ruby. For example: How do I write a Hash literal?

Thanks to ujihisa for a great help to write it.

Vim: ku 0.2.4

2009-05-29T02:37:54 / vim, release / comment

Vim plugin ku 0.2.4 has been released. This version includes a bugfix, a minor improvement on the default configuration of the ku buffer, and new feature to explore the content of an archive in source file. See also changelog on ku 0.2.4 for the details.

The details of "archive" feature are as follows: ku lists the content of an archive as if it is an ordinary directory.

Vim: ku 0.2.4 - new feature #2

And various actions to extract the whole or a partial content of an archive are also provided.

Currently, these new features are not tested well and somewhat limited. For example, only zip format is supported and the way to determine whether a given item is a zip file or not is not so good. I'll fix and improve such limitations soon. Welcome your feedbacks.

I noticed that there is a serious bug to use ku in version 0.2.4. I've fixed it and released as version 0.2.4.1. Please download it if you already downloaded 0.2.4.

Vim: Hack #16: Bookmark a file

2009-05-25T02:37:43 / vim / comment

Wrote an article Hack #16: Bookmark a file for Vim Hacks Project at vim-users.jp.

Vim: metarw 0.0.4

2009-05-24T15:00:07 / vim, release / comment

metarw 0.0.4 has been released. Add a hook to do something after writing. Fix a minor bug. See also changelog on metarw 0.0.4 for the details.

Today's Shopping: Floppy Cube

2009-05-23T00:25:27 / puzzle, rubik / comment
Floppy Cube, with my lovely doll.

Bought a Floppy Cube, a variant of Rubik's Cube. I want to get it since I knew about it - about 4 or more years ago. Now it is available at stores. Yay!

Even there are many variants of Rubik's Cube, I believe that it is one of the most wonderful variants because of its simpleness and misteriousness. While Rubik's Cube consits of 3*3*3 subcubes and its shape is a cube, Floppy Cube consists of 3*3*1 subcubes and its shape is like a board. So it's a simple puzzle to solve, but its structure is too mysterious. Why aren't corner subcubes disintegrated as I turn an edge? How is it constructed? Amazing!

Today's event: @mootoh's invitation to dinner

2009-05-18T01:20:22 / dairy / comment

Today, @eikom and I were invited to dinner from @mootoh. It was very yummy!

Then we talked about many subjects - fundamental philosophy on software development, text editors, keyboards (Kinesis and others), TV, animations, GUNDAM W, figures, dolls, etc. It was very interesting and fun. As we talked so much, @eikom and I almost missed today's last train.

Thanks a lot @mootoh and @eikom for the great time!

Yesterday's event: Found an extremely lovely doll

2009-05-17T15:05:26 / doll / comment

Yesterday, I went window-shopping around Akihabara, especially for dolls and related items, then I found an extremely lovely doll at Yellow Submarine Rouge. That's a teeny-weeny custom doll based on FELIX Brownie Series who Hanakago no Kobeya (花かごの小部屋) brought up. Though I felt that she's lovely when I saw several photos of her at the online shop before, my impression of the real existence of her is completely different from the photos. It's extremely lovely!

Today's Shopping: Doll Clothes

2009-05-17T00:58:03 / doll, shopping / comment
Today's Shopping: Doll clothes
My doll equips the clothes.

Bought the following clothes for my doll at Azone Label Shop Akihabara:

Vim: ku 0.2.2 / ku-metarw 0.1.2

2009-05-15T23:53:48 / vim, release / comment

I've updated two Vim plugins; ku 0.2.2 and ku-metarw 0.1.2. These are bufix releases especially on Microsoft Windows. See changelog on ku 0.2.2 and changelog on ku-metarw 0.1.2 for the details.

Vim: metarw-git 0.0.3

2009-05-13T02:24:06 / vim, release / comment

metarw-git 0.0.3 has been released. Fix several bugs when completing branches.

git: log --graphの出力がカラフルになってる

2009-05-12T02:56:58 / git / comment
Colorful git log --graph

gitの最新バージョンでgit log --graphのグラフ出力がカラフルになってました。git version 1.6.3.9.g6345dで確認。どうも4月半ばの時点でこの機能は実装されていて、それが最近になってmasterに統合されたようです。複雑なグラフになると見難く感じていたのでこれは非常に便利。雰囲気や色合いからrepo.or.czでのコミットログの可視化に近いものがあって、個人的にはますます良い感じです。まあ可視化だけならGUIのフロントエンドを使えば良いことですし、見た目の点でもそちらの方が良いのは確かなのですが、端末内でちゃちゃっとできることが重要ですからね。

Vim: 拙作プラグインのドキュメントのHTML版を用意した

2009-05-10T01:17:49 / vim, git, github / comment

拙作VimプラグインのドキュメントのHTML版を用意しました。GitHub Pagesを利用しています。今回で初めてGitHub Pagesの便利さを実感した気がします。ドキュメント公開についての機構の詳細はgithub上にて公開されていますので、よければ参考にしてください。恐らくこの中で最も有用なものはVimを利用したバッチ処理のノウハウでしょう。

なお:helpからHTMLの変換はまだ適当です。具体的には:helpにおけるリンクがHTMLにおいてもリンクになっていません。このままでは使いものにはならないのですぐに修正する予定です。本当はvimdocのシステムからコンバーターを流用しようと思ったのですが、どこに何があるやらさっぱりなので諦めました。

リンクについての変換も行うよう修正しました。例: :help ku-auto-component-completion。後はまともなHTMLにすることかな。

git: 独自のサブコマンド(あるいはちょっと複雑なalias)を定義する際のtips

2009-05-08T00:34:59 / git, tips / comment

問題

gitにはadd、blame、commitなどの標準のサブコマンド以外にも独自のサブコマンドを定義できます(正確にはこの機能の名称はaliasですし、本来はそういう用途で導入されたものだとも思うのですが、私としてはこの説明の方がしっくりくるので以降ではaliasとは呼びません)。標準サブコマンドに対する単純なエイリアスを定義したり、単に外部コマンドを実行するだけのものなら何も問題はありません。

しかし、ちょっと複雑なものを定義しようとすると話は少々面倒になってきます。処理自体をスクリプトとして分離してそれを実行するだけのサブコマンドを定義するのも一つの方法なのですが、gitのサブコマンドとして定義するようなケースではスクリプトを分離するほどの規模でない場合が多く、もし分離するとなると管理対象のファイルが増えるため面倒です。できるだけ単一の設定ファイル(~/.gitconfig)に定義をまとめられないでしょうか。また、その設定ファイル中に記述するにしても、コマンドライン引数に対してちょっとした処理を行いたい場合や、コマンドラインの内容に特殊記号を含む場合はどう記述すればいいのでしょうか。

解決方法

直接コマンドを記述せず、もう一段階シェルを噛ませます。~/.gitconfig中の記述に際しては以下のものをテンプレートとして用いれば良いでしょう:

[alias]
my-subcommand = "!$SHELL -c 'a short shell script' __dummy__"

なお、スクリプトに"\が含まれる場合は\"\\のようにエスケープしなければなりません。

具体例

以下のようなサブコマンドlrを作ることにしましょう(list recent commitsの略です)。

シェルスクリプトとして記述する場合は以下のようになります:

n=10
1="${1:-$n}"
if [ "${1##[0-9]*}" != "" ]
then
  t="$1"
  1="${2:-$n}"
  2="$t"
fi
git --no-pager log --pretty=oneline --reverse -"$1" "${2:-HEAD}"

これを~/.gitconfigなどに記述する場合は以下のように変換します:

[alias]
lr = "!$SHELL -c '                                                         \n\
         n=10                                                              \n\
         1=\"${1:-$n}\"                                                    \n\
         if [ \"${1##[0-9]*}\" != \"\" ]                                   \n\
         then                                                              \n\
           t=\"$1\"                                                        \n\
           1=\"${2:-$n}\"                                                  \n\
           2=\"$t\"                                                        \n\
         fi                                                                \n\
         git --no-pager log --pretty=oneline --reverse -\"$1\" \"${2:-HEAD}\"\
       ' __dummy__"

解説

独自サブコマンドで外部コマンドを実行する場合はfoo = !bar!を前置しますが、この!以降の文字列はgitコマンドの実行時に指定されたコマンドライン引数と共にsystem(3)に渡されます。例えば:

foo = !if [ x$1 = x ]; then echo true; else echo false; fi

などと書いてgit foo barと実行すると、実際に実行されるものは以下のようになります:

if [ x$1 = x ]; then echo true; else echo false; fi bar

この場合、コマンド実行時に渡したbar$1に代入されず空文字列となりますし、そもそも展開結果は構文エラーです。

ただ引数を後ろに並べるだけで十分ならば問題ないのですが、上記の例のように引数を入れ替えたりデフォルト値を定義するとなるとそうはいきません。このような処理を行うためにはシェルを経由させる必要があります(system(3)で一度シェルを経由していますから、「もう一段階シェルを噛ませる」という訳です)。

また、サブコマンドに限らず設定ファイルの値の記述中では、行末に\で行継続が行なえますし、\nで改行文字を表現できます。このことを利用してシェルスクリプトをそのまま機械的に変換し、設定ファイル中に埋め込むことが可能です。

なお、ここではシェルとしてBourne系のシェルを仮定しています。そうでないシェルを利用している場合は$SHELLやそれに対するコマンドラインオプションなどは適宜読み替えてください。

TODO: 次はこの埋め込み作業を自動化する。具体的には、シェルスクリプトを設定ファイル中にそのまま書いておいて、よしなに変換したものを~/.gitconfigに置くようにする。理由: 埋め込んだスクリプトが読み難いから。

Vim: fakeclip 0.2.3 / metarw-git 0.0.2

2009-05-06T04:05:13 / vim, release / comment

fakeclip 0.2.3とmetarw-git 0.0.2をリリースしました。ちょっとしたバグ修正のみ。またfakeclipをMac OS Xで利用する際の注意点についてドキュメントの加筆・修正を行いました。ujihisaさんが長らくはまっていた問題がようやく解決した記念。

gitのalias関係で2つ問題を見つけた

2009-05-05T21:50:04 / git, question / comment

gitのalias関係で問題を2点ほど見つけました。ひとつはGIT_TRACEを有効にするとクラッシュすることで、もうひとつはaliasで展開される文字列にダブルクォート(")が含まれている場合の挙動がおかしいことです。以下詳細:

GIT_TRACEを有効にするとalias展開時にクラッシュする

以下の環境で再現できる:

$ git remote show origin
* remote origin
  URL: git://repo.or.cz/git.git
  Remote branch merged with 'git pull' while on branch master
    master
  Tracked remote branches
    html
    maint
    man
    master
    next
    pu
    todo

$ git --version
git version 1.6.2.rc0.90.g0753

$ git show HEAD | grep commit
commit 3536ae331014c68a25c80b3fb530a19c8dee0f11

$ uname -a                   
Darwin avril 9.6.1 Darwin Kernel Version 9.6.1: Sun Dec 21 19:45:33 PST 2008; root:xnu-1228.9.75~4/RELEASE_I386 i386 i386 MacBook5,2 Darwin

$ git config --get alias.l1
log --pretty=oneline

$ GIT_TRACE=1 git l1         
trace: exec: 'git-l1'
trace: run_command: 'git-l1'
trace: exec 'git-l1' failed: No such file or directory
[1]    41772 segmentation fault  GIT_TRACE=1 git l1

コードを斜め読みした感じでは、恐らく文字列処理絡みの些細なことだと思います。

展開される文字列にダブルクォート(")が含まれるaliasの展開がおかしい

元々、以下のようなaliasを定義していました。これはHEADの最新のコミット10個を古いものから順に表示するものです。

lr = !git l1 | head | tac

最近になってこれを任意のブランチにおける最新Nコミットを表示するように拡張したくなったので、以下のような定義に書き換えました(読み易さのために改行・インデントを入れていますが、実際は一行です):

lr = !$SHELL -c '
        n=10;
        1="${1:-$n}";
        if ! [ "${1##[0-9]*}" = "" ]; then
          t="$1";
          1="${2:-$n}";
          2="$t";
        fi;
        git --no-pager l1 --reverse -"$1" "${2:-HEAD}"
      ' __dummy__

ところがこれをgitが期待通りに展開してくれません。私としては!以降をそのままsystem(3)に渡すものだとばかり思っていたのですが、何やら処理を行なっているようで、その結果として以下のように展開されてしまいます:

$ git config --get alias.lr
!$SHELL -c '1=${1:-10}

どうもダブルクォート(")の有無でこの問題が発生するかどうかが決まるようなのですが、どのみちこの挙動がバグなのか意図されたものなのかが不明です。

取り敢えずgitのメーリングリストにポストはしておきました。

後者の件については"を\"とエスケープしたうえで全体を"で括ることで解決しました。軽くコードを調べたところ、"が抜け落ちることについては設定ファイルのパースに由来することで、それ自体は納得できました。ただ途中で切り捨てられることについてはまだよく分かりません。

問題とは全く関係ありませんが、設定ファイルの記述において行末に\で行継続ができることを教えてもらいました。なるほどなるほど。ただ1行にまとまらないと簡単にsortできないので困りもの(aliasの記述は名前でsortしてるので)。

Vim: ku 0.2.0 - An interface for anything

2009-05-04T12:10:35 / vim, release / comment

ku 0.2.1をリリースしました。細かいバグフィックスのみ。

最近の朝の行動

2009-05-03T21:03:48 / diary / comment
  1. 目が開く。
  2. もそもそと起き上がる。
  3. 徳用バニラアイス(1kg)をいくらかコーヒーカップによそう。
  4. もそもそと頬張る。
  5. 目が覚めてくる。
  6. アイスが微妙に溶けて残ってるコーヒーカップにインスタントコーヒーの粉を入れてお湯を注ぐ。
  7. もそもそと飲む。
  8. 寝る。

Mac OS X: hostnameの出力がインターネット接続の有無で変化してしまう

2009-05-01T00:33:24 / mac, question / comment

前々から不思議に思っていたのですが、私の使用しているMacBookではhostnameの出力がインターネットの接続状況によって変化します。

$ hostname  # while not conntected to the Internet
avril.local

$ hostname  # while connected to the Internet
1-2-3-4.example.com

些細なことなのですが、何故こうなっているのか不思議ですし、何より気持ち悪い。どうにかして前者の方が常に出力されるようにしたいのですが、何を調べれば良いのかさっぱりです。