8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ポケモンに格言を喋らせる

Last updated at Posted at 2017-02-01

モチベーション

ジョークコマンドの fortunecowsay を組み合わせると牛がいろいろ喋ってくれるんですが、

$ fortune | cowsay
 _____________________________________
/ QOTD:                               \
|                                     |
| Flash! Flash! I love you! ...but we |
| only have fourteen hours to         |
|                                     |
\ save the earth!                     /
 -------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

cowsay のポケモンが喋ってくれる版があったので、
https://github.com/possatti/pokemonsay

日本語で格言を喋らせてシュールにしてみようかと。

スクリーンショット 2017-02-01 18.21.23.png

とりあえず fortunecowsay は入ってる前提で進めます。

名言をダウンロード

とりあえずここから「星が見える名言集」 fortune-meigen.tar.gz を落としてきて、
ひとまず ~/.fortune に展開。

文字コードが euc-jp なので utf8 に変換しておきます。

$ cd ~/.fortune
$ nkf -w meigen > meigen.utf8
$ strfile meigen.utf8

cowsayの日本語対応

ほぼこちらに書いてある通りだけど、1箇所 binmode STDOUT, ":utf8"; を追加してあります。

diff置いときます。
https://gist.github.com/arc279/fa2df27ec8a0093be4daf9aadacde2a8

pokemonsay を入れる

を落としてきて、./install.sh すると、~/.pokemonsay/cows にcowファイルが展開されます。

ここでおもむろに

$ cd ~/.pokemonsay/cows
$ sed -i '/binmode/s/^/#/g' *

一括で binmode STDOUT, ":utf8"; をコメントアウト。

実行

~/bin/pokemonsay にコマンド入ってると思うので、

$ fortune .fortune/meigen.utf8 | ~/bin/pokemonsay

とかやると喋ってくれます。
冒頭の画像参照。

.bashrc とかに書いとくとわりとうざいです。

最後の行にタブ文字が入ってる都合で、出典の人名が長い場合とかだと、
吹き出しの長さがうまく計算できないくて折り返しのあたりで文字化けするので、
-w 100 とかで吹き出し少し広めにとっておくと良いと思います。

その他参考

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?