はてブロ@ama_ch

https://twitter.com/ama_ch

DropBoxを使ってUnix環境を同期させる方法

いつかやろうと思って忘れてた、DropBoxを使って、まっさらな環境から5分で継続的で快適な環境を作る方法  - a2c.get.diaryを実践してみました。


まずDropBoxドットファイル置き場を作る。

% mkdir ~/Dropbox/dotfiles

同期させたいドットファイルをここにコピー。

% cd ~
% for i in {.zshrc,.zshrc.mine,.zsh_history,.screenrc,.emacs.el,.emacs.d};do cp -r $i ~/Dropbox/dotfiles; done

ドットファイル置き場に以下のスクリプトを置く。

#!/bin/sh
path=$(pwd)

for i in {.vimrc,.zshrc,.zshrc.mine,.zsh_history,.screenrc,.emacs.el,.emacs.d};
do
    mv ~/$i ~/$i.org
    ln -s $path/$i ~/$i
done

参照元エントリーのlnがfor内で動いていなかったようだけど、絶対パスで書いてみたら動きました。
あとはこのスクリプトを実行すればオッケー!シンボリックリンクが作成され、以後編集したら適宜同期されます。
これ以外も同じ要領で色々同期させることができます。僕はFirefoxのProfileなんかも同期させているので、DropBoxさえあればどこでも同じブラウザが使えます。DropBox便利すぎる!

MacBookのメモリを増設した!

去年の春に購入した白MacBookちゃんのメモリを増設しました。
購入時に1GB→2GBに増設したものの、最近は色々立ち上げてるとメモリの空きが17MBとかになってやばい。これはどうにかしないと!

メモリ選択のポイント

といっても全然詳しくないのでテキトーに選びました。

  • Apple純正はクソ高い(2GBで15,000円*1
  • 素人だからバルクは怖い><
  • 田舎暮らしだからネットで買えるやつ


・・・で、これになりました。

Transcend JetRam ノートPC用増設メモリ PC2-5300(DDR2-667) 2GB 永久保証 JM667QSU-2G

Transcend JetRam ノートPC用増設メモリ PC2-5300(DDR2-667) 2GB 永久保証 JM667QSU-2G


2枚で4000円ちょい。2枚セットのものもあったけど、これを2枚買った方がお得という罠でした。
トランセンドは安心の永久保証!ただし、購入後30日以内にhttp://www.transcend.co.jp/registrationで製品の登録をする必要があります。
製品のシリアルナンバーは本体に書いてあるので、購入したら挿す前にこちらで製品登録をしましょう。

メモリ交換作業

サポートサイトのMacBook:メモリの取り付け方法が詳しいです。

  • 電源を落とす
  • ケーブル類を全部はずす
  • 裏返してコインを使いバッテリーをはずす
  • 内部のネジを3本はずす
    • 小さすぎてうちにあるドライバーじゃはずせなかった><
    • ホームセンターに行って買ってきた、230円。
  • ネジは完全に外れないようになっているので、適当に緩める
  • L字型の金具をはずす
  • どの深さまで差し込めばいいのか、メモリの刺さり具合を確認しておく
  • レバーを引いてメモリをはずす
  • メモリを挿入する。かなり力を込めてぐっと入れる必要がある
  • 逆の手順でパーツを元に戻す


所要時間は10分程度。サイズの合うドライバーさえあればかなり簡単!

無事に4GBになりました。今まで空き領域が数十MBしかなかったのが、いきなり2GB空きが出てサクサクです。
特に起動に時間がかかっていたアプリケーションの立ち上げが目に見えて早くなりました。メモリ増設だけでここまで変わる、すごい!

*1:http://store.apple.com/jp/memorymodel/ME_13_2_1_MB

コマンドからファイル印刷のまとめ

nkf + e2psを使ってファイルを印刷する方法。
e2psはテキストファイルをPostScriptに変換するツールなんだけど、UTF-8に対応していないのでnkfもインストールした。


nkfMacPortsで。

% sudo port install nkf


e2psをWtSeries : UNIXツールからダウンロードして、解凍。

% cd e2ps-4.34

そのままMacでmakeするとエラーが出るので、ps-font.cの14〜52行の行末にバックスラッシュを追加する。
参考:Debian GNU/Linux から Mac OS X に移行したメモ
ps-font.c

char *gsFonts = "Times-Roman\
Times-Italic\
Times-Bold\
Times-BoldItalic\
--- 中略 ---
Ryumin-Light.Hiragana\
Ryumin-Light.Katakana\
Gothic-Meduim.Hiragana\
Gothic-Medium.Katakana\
";

これでmakeが通るようになる。

% cd e2ps-4.34
% make
% sudo make install


これでインストールは完了!あとはこんな風に使う。

% nkf -e foo.txt | e2ps -size 11 -box | lpr -P bar

このコマンドでフォントサイズ11,枠線ありの設定になる。
ubulog: Emacsから印刷するを参考にさせていただきました。


最後に、e2psのREADMEから使い方を抜粋。

○使い方
・e2ps [引数] [ファイル名・・・]
    ファイルを(複数)指定しても,標準入力でテキストデータを入力しても
    構いません.結果はPostScriptファイルとして出力されます.
・e2lpr は,直接プリンタへ出力します.
・e2ps -h で引数のヘルプが出ます.主に使用する引数を以下の通りです.

    -p			: ポートレイト (縦向き)
    -p2			: ポートレイト2面印刷 (デフォルト)
    -p4			: ポートレイト4面印刷		例: 1 2	
							    3 4
    -pv4		: ポートレイト4面縦順印刷	例: 1 3	
							    2 4
    -l			: ランドスケープ (横向き)
    -l2			: ランドスケープ2面印刷
    -l4			: ランドスケープ4面印刷
    -lv4		: ランドスケープ4面縦順印刷
    -box		: ページの枠を印刷
    -size fontsize	: フォントサイズ (10.0)
    -line line		: ページの最大行数 (66)
    -nh			: ヘッダをなくす
    -Pprinter		: プリンタ設定 (lp)
    -h | --help		: ヘルプを表示する
    -v | --version	: バージョンを表示する


○難しい引数の解説
・-af		(デフォルト: Courier)
・-abf		(デフォルト: Courier-Bold)
・-abif		(デフォルト: Courier-BoldOblique)
    PostScritpのアスキーフォント(太字,太字斜体)を指定します.
    -fl 引数で,フォントのリストが見られますが,すべて使えるわけでは
    ありません.指定できるフォントは,プリンタに依存します.
	例:
	-af Times-Roman		Times-Romanフォントで印刷されます

・-afw		(デフォルト: 0.6)
・-afh		(デフォルト: 1.0)
・-kfw		(デフォルト: 1.2)
・-kfh		(デフォルト: 1.0)
    印刷する文字の幅や高さの倍率を指定します.
    -afw, -afh がアスキーフォントの幅と高さで,
    -kfw, -kfh が漢字フォントの幅と高さです.
    -ahf,-kfh ともに,1.0以上の値は無視されます.
    Courierフォントは,高さに対してもともと 0.6倍の幅であるため,
    アスキーフォントのデフォルト値が 0.6 になっています.
    漢字フォントは,幅も高さも同じ大きさですが,通常の印刷では
    Courierフォントに合わせて 1.2倍の幅にして印刷しています.
    そのため,デフォルト値が 1.2 になっています.
    	例:
	-afw 0.3	アスキーフォントが通常の半分の幅で印刷されます
	-afw 1.2	アスキーフォントが通常の2倍の幅で印刷されます
	-afh 0.5	アスキーフォントが通常の半分の高さで印刷されます
	-afh 1.2	アスキーフォントは通常と同じ高さで印刷されます
	-kfw 1.0	漢字フォントが隙間なく密に印刷されます
	-kfw 0.5	漢字フォントが通常の半分の幅で印刷されます
	-kfw 2.0	漢字フォントが隙間が通常よりも広く印刷されます
	-kfh 0.5	漢字フォントが通常の半分の高さで印刷されます
	-kfh 1.2	漢字フォントは通常と同じ高さで印刷されます
・-ohp
    OHPに印刷するように,フォントを大きく(25.0)して,へッダを印刷
    しないようにします.

・-date
    ページ左上に印刷される日付の文字列を指定します.
    日本語も指定できます.

・-head
    ページ中央上に印刷されるファイル名の文字列を指定します.
    日本語も指定できます.

・-page
    ページ右上に印刷されるページの文字列を指定します.
    「指定した文字+ページ数」のように印刷されます.
    日本語も指定できます.

screenを縦に横に分割しまくろう

screenてデフォルトだと水平分割しかできないんですよね。MacBookのような横に長い画面だと、左右に分割した方が効率が良いのは明らかです。うーん何とかしたい!
おしえて!google先生
「screen 分割 左右」とか「screen 分割 (縦|垂直)」とか「screen vsplit」などと検索しまくった末に、垂直に分割できるcvsがあるらしいので早速導入してみました。


参考にしたページ:
:wq - blog » Blog Archive » Compiling screen from CVS on OSX for vertical split.
CodeSnippets: Vertical & horizontal split for man screen


以下のコマンドを実行します。

% cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/screen co screen
% cd screen/src
% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-maxargs
% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-windowsize
% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-pty.c
% ./configure --enable-colors256
% make
% sudo make install

あとは普通にscreenを起動して、「escape |」で垂直分割が使えました。「|」はアルファベットの「エル」ではなく縦棒の方なので注意が必要です。
これでscreenを縦に横に分割しまくれるようになりました。僕がEmacsで大好きな3ペイン表示も余裕です!やったね!!


せっかく分割ができるようになったので、分割操作も含めたウィンドウ操作のキーバインドEmacs風に設定してみましょう。
.screenrcに以下の設定を記述します。

bind -c REGION o focus down
bind -c REGION p focus up
bind -c REGION 0 remove
bind -c REGION 1 only
bind -c REGION 2 split
bind -c REGION 3 split -v
bind -c REGION \^ resize +2
bind -c REGION } resize +2
bind -c REGION { resize -2
bind x command -c REGION

これでまるでEmacsがごとくウィンドウを操作できます!
便利すぎて鼻血が出るのでぜひ導入しましょう!


インストール作業ログ:

14:32 ama-ch% cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/screen co screen                                                                                      [~]
cvs checkout: Updating screen
U screen/COPYING
U screen/mktar.pl
cvs checkout: Updating screen/incoming
cvs checkout: Updating screen/incoming/howto
U screen/incoming/howto/emulate_vims_help.txt
cvs checkout: Updating screen/patches
U screen/patches/bill_pursell_fFtT_402.patch
U screen/patches/screen-4.0.2.dif
U screen/patches/screen-__P.diff
U screen/patches/screen-gcc4.diff
cvs checkout: Updating screen/src
U screen/src/.iscreenrc
U screen/src/COPYING
U screen/src/ChangeLog
U screen/src/FAQ
U screen/src/INSTALL
U screen/src/Makefile
U screen/src/Makefile.in
U screen/src/NEWS
U screen/src/NEWS.3.5
U screen/src/NEWS.3.6
U screen/src/NEWS.3.7
U screen/src/NEWS.3.9
U screen/src/README
U screen/src/TODO
U screen/src/acls.c
U screen/src/acls.h
U screen/src/ansi.c
U screen/src/ansi.h
U screen/src/attacher.c
U screen/src/braille.c
U screen/src/braille.h
U screen/src/braille_tsi.c
U screen/src/comm.c
U screen/src/comm.h.dist
U screen/src/comm.sh
U screen/src/config.h.in
U screen/src/configure
U screen/src/configure.in
U screen/src/display.c
U screen/src/display.h
U screen/src/encoding.c
U screen/src/extern.h
U screen/src/fileio.c
U screen/src/help.c
U screen/src/image.h
U screen/src/input.c
U screen/src/install.sh
U screen/src/kmapdef.c.dist
U screen/src/layer.c
U screen/src/layer.h
U screen/src/loadav.c
U screen/src/logfile.c
U screen/src/logfile.h
U screen/src/mark.c
U screen/src/mark.h
U screen/src/misc.c
U screen/src/nethack.c
U screen/src/os.h
U screen/src/osdef.h.in
U screen/src/osdef.sh
U screen/src/patchlevel.h
U screen/src/process.c
U screen/src/pty.c
U screen/src/putenv.c
U screen/src/resize.c
U screen/src/sched.c
U screen/src/sched.h
U screen/src/screen.c
U screen/src/screen.h
U screen/src/search.c
U screen/src/socket.c
U screen/src/teln.c
U screen/src/term.c
U screen/src/term.h.dist
U screen/src/term.sh
U screen/src/termcap.c
U screen/src/tty.c.dist
U screen/src/tty.sh
U screen/src/utmp.c
U screen/src/window.c
U screen/src/window.h
cvs checkout: Updating screen/src/BUGS
cvs checkout: Updating screen/src/CONVERT
cvs checkout: Updating screen/src/PATCHES
cvs checkout: Updating screen/src/PATCHES/DONE
cvs checkout: Updating screen/src/TEST
cvs checkout: Updating screen/src/config
cvs checkout: Updating screen/src/doc
U screen/src/doc/FAQ
U screen/src/doc/Makefile.in
U screen/src/doc/README.DOTSCREEN
U screen/src/doc/fdpat.ps
U screen/src/doc/install.sh
U screen/src/doc/make.help
U screen/src/doc/screen.1
U screen/src/doc/screen.info
U screen/src/doc/screen.info-1
U screen/src/doc/screen.info-2
U screen/src/doc/screen.info-3
U screen/src/doc/screen.info-4
U screen/src/doc/screen.info-5
U screen/src/doc/screen.texinfo
U screen/src/doc/window_to_display.ps
cvs checkout: Updating screen/src/etc
U screen/src/etc/ccdefs
U screen/src/etc/completer.zsh
U screen/src/etc/countmail
U screen/src/etc/etcscreenrc
U screen/src/etc/gr-braille.tbl
U screen/src/etc/gs-braille.tbl
U screen/src/etc/mkinstalldirs
U screen/src/etc/newsyntax
U screen/src/etc/newsyntax38
U screen/src/etc/screenrc
U screen/src/etc/toolcheck
U screen/src/etc/us-braille.tbl
cvs checkout: Updating screen/src/terminfo
U screen/src/terminfo/8bits
U screen/src/terminfo/README
U screen/src/terminfo/checktc.c
U screen/src/terminfo/screencap
U screen/src/terminfo/screeninfo.src
U screen/src/terminfo/test.txt
U screen/src/terminfo/tetris.c
cvs checkout: Updating screen/src/terminfo/s
cvs checkout: Updating screen/src/utf8encodings
U screen/src/utf8encodings/01
U screen/src/utf8encodings/02
U screen/src/utf8encodings/03
U screen/src/utf8encodings/04
U screen/src/utf8encodings/18
U screen/src/utf8encodings/19
U screen/src/utf8encodings/a1
U screen/src/utf8encodings/bf
U screen/src/utf8encodings/c2
U screen/src/utf8encodings/c3
U screen/src/utf8encodings/c4
U screen/src/utf8encodings/c6
U screen/src/utf8encodings/c7
U screen/src/utf8encodings/c8
U screen/src/utf8encodings/cc
U screen/src/utf8encodings/cd
U screen/src/utf8encodings/d6
14:33 ama-ch% cd screen/src                                                                                                                                                    [~]
14:43 ama-ch% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-maxargs                                          [~/screen/src]
patching file ansi.c
14:43 ama-ch% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-windowsize                                       [~/screen/src]
patching file resize.c
Hunk #1 FAILED at 682.
1 out of 1 hunk FAILED -- saving rejects to file resize.c.rej
14:44 ama-ch% patch < /opt/local/var/macports/sources/rsync.macports.org/release/ports/sysutils/screen/files/patch-pty.c                                            [~/screen/src]
patching file pty.c
14:44 ama-ch% ./configue --enable-colors256                                                                                                                         [~/screen/src]
./configure is correct? [n,y,a,e]: y
this is screen version 4.0.3
checking for prefix by checking for screen... /opt/local/bin/screen
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking whether gcc needs -traditional... no
checking for library containing strerror... none required
checking for gawk... gawk
checking for a BSD-compatible install... /usr/bin/install -c
configure: checking for buggy tools...
- sh  is 'GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)'.
checking if a system-wide socket dir should be used... yes
checking for the socket dir... (eff_uid ? "/tmp/uscreens" : "/tmp/screens")
configure: checking for MIPS...
configure: checking for Ultrix...
rm: conftest.dSYM: is a directory
configure: checking for butterfly...
rm: conftest.dSYM: is a directory
configure: checking for POSIX.1...
- you have a POSIX system
rm: conftest.dSYM: is a directory
configure: checking for System V...
configure: checking for sequent/ptx...
rm: conftest.dSYM: is a directory
configure: checking SVR4...
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
no
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
configure: checking for Solaris 2.x...
rm: conftest.dSYM: is a directory
configure: checking BSD job jontrol...
- you have jobcontrol
configure: checking setreuid...
configure: checking seteuid...
configure: checking select...
configure: checking fifos...
- your fifos are usable
configure: checking for broken fifo implementation...
- your implementation is ok
configure: checking sockets...
- your sockets are usable
configure: checking socket implementation...
- you are normal
- both sockets and fifos usable. let's take fifos.
configure: checking select return value...
- select is ok
configure: checking for tgetent...
configure: checking libcurses...
- you use the terminfo database
configure: checking ospeed...
configure: checking for /dev/ptc...
configure: checking for SVR4 ptys...
checking for getpt... no
configure: checking for ptyranges...
rm: conftest.dSYM: is a directory
configure: checking default tty permissions/group...
- pty mode: 0620, group: 4
configure: checking getutent...
configure: checking getutent with -lgen...
configure: checking ut_host...
checking utempter.h usability... no
checking utempter.h presence... no
checking for utempter.h... no
configure: checking for libutil(s)...
configure: checking getloadavg...
rm: conftest.dSYM: is a directory
assuming posix signal definition
configure: checking for crypt and sec libraries...
configure: checking crypt...
configure: checking IRIX sun library...
configure: checking syslog...
rm: conftest.dSYM: is a directory
configure: checking wait union...
configure: checking for termio or termios...
configure: checking getspnam...
configure: checking getttyent...
configure: checking fdwalk...
configure: checking whether memcpy/memmove/bcopy handles overlapping arguments...
checking long file names... yes
checking for vsprintf... yes
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for setenv... yes
checking for nl_langinfo(CODESET)... yes
checking for library containing gethostname... none required
checking for rename... yes
checking for fchmod... yes
checking for fchown... yes
checking for strerror... yes
checking for lstat... yes
checking for _exit... yes
checking for utimes... yes
checking for vsnprintf... yes
checking for getcwd... yes
checking for setlocale... yes
checking for strftime... yes
checking for the global screenrc file... "/opt/local/etc/screenrc"
checking for the utf8-encodings location... "/opt/local/share/screen/utf8encodings"
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing default commands

Now please check the pathnames in the Makefile and in the user
configuration section in config.h.
Then type 'make' to make screen. Good luck.

14:48 ama-ch% make                                                                                                                                                  [~/screen/src]
CPP="gcc -E " srcdir=. sh ./osdef.sh
AWK=gawk CC="gcc -g -O2" srcdir=. sh ./comm.sh
AWK=gawk srcdir=. sh ./term.sh
gcc -c -I. -I.    -g -O2 screen.c
In file included from screen.h:144,
                 from screen.c:81:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from screen.c:81:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 ansi.c
In file included from screen.h:144,
                 from ansi.c:31:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from ansi.c:31:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 fileio.c
In file included from screen.h:144,
                 from fileio.c:33:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from fileio.c:33:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 mark.c
In file included from screen.h:144,
                 from mark.c:27:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from mark.c:27:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 misc.c
In file included from screen.h:144,
                 from misc.c:29:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from misc.c:29:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 resize.c
In file included from screen.h:144,
                 from resize.c:37:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from resize.c:37:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 socket.c
In file included from screen.h:144,
                 from socket.c:37:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from socket.c:37:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
socket.c: In function ‘FinishAttach’:
socket.c:1321: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
gcc -c -I. -I.    -g -O2 search.c
In file included from screen.h:144,
                 from search.c:27:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from search.c:27:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
sh ./tty.sh tty.c
gcc -c -I. -I.    -g -O2 tty.c
In file included from screen.h:144,
                 from tty.c:57:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from tty.c:57:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 term.c
gcc -c -I. -I.    -g -O2 window.c
In file included from screen.h:144,
                 from window.c:34:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from window.c:34:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 utmp.c
In file included from screen.h:144,
                 from utmp.c:29:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from utmp.c:29:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:82: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:83: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:84: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:85: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:87: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘RemoveLoginSlot’:
utmp.c:309: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:309: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘SetUtmp’:
utmp.c:405: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘RemoveUtmp’:
utmp.c:499: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:499: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: At top level:
utmp.c:643: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:672: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c:682: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘getutslot’:
utmp.c:686: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘pututslot’:
utmp.c:695: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘makedead’:
utmp.c:714: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
utmp.c: In function ‘makeuser’:
utmp.c:729: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 loadav.c
In file included from screen.h:144,
                 from loadav.c:41:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from loadav.c:41:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 putenv.c
gcc -c -I. -I.    -g -O2 help.c
In file included from screen.h:144,
                 from help.c:28:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from help.c:28:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 termcap.c
In file included from screen.h:144,
                 from termcap.c:26:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from termcap.c:26:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 input.c
In file included from screen.h:144,
                 from input.c:26:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from input.c:26:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
input.c: In function ‘Input’:
input.c:145: warning: assignment from incompatible pointer type
gcc -c -I. -I.    -g -O2 attacher.c
In file included from screen.h:144,
                 from attacher.c:30:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from attacher.c:30:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 pty.c
In file included from screen.h:144,
                 from pty.c:30:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from pty.c:30:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 process.c
In file included from screen.h:144,
                 from process.c:44:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from process.c:44:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
process.c: In function ‘DoAction’:
process.c:2073: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
process.c:2075: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
process.c:2077: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
process.c:2079: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
process.c:2081: warning: passing argument 3 of ‘display_wlist’ from incompatible pointer type
process.c:3970: warning: comparison between pointer and integer
process.c:4138: warning: assignment makes pointer from integer without a cast
process.c: In function ‘NextWindow’:
process.c:4955: warning: initialization from incompatible pointer type
process.c:4963: warning: comparison of distinct pointer types lacks a cast
process.c: In function ‘PreviousWindow’:
process.c:4977: warning: initialization from incompatible pointer type
process.c:4985: warning: comparison of distinct pointer types lacks a cast
process.c: In function ‘SelectLayoutFin’:
process.c:5499: warning: assignment makes pointer from integer without a cast
gcc -c -I. -I.    -g -O2 display.c
In file included from screen.h:144,
                 from display.c:32:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from display.c:32:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
display.c: In function ‘CreateLayout’:
display.c:4455: warning: return from incompatible pointer type
display.c: In function ‘SaveLayout’:
display.c:4471: warning: assignment from incompatible pointer type
display.c: In function ‘NewLayout’:
display.c:4549: warning: assignment from incompatible pointer type
gcc -c -I. -I.    -g -O2 comm.c
gcc -c -I. -I.    -g -O2 kmapdef.c
gcc -c -I. -I.    -g -O2 acls.c
In file included from screen.h:144,
                 from acls.c:45:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from acls.c:45:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 braille.c
In file included from screen.h:144,
                 from braille.c:33:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from braille.c:33:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 braille_tsi.c
In file included from screen.h:144,
                 from braille_tsi.c:30:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from braille_tsi.c:30:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 logfile.c
In file included from screen.h:144,
                 from logfile.c:30:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from logfile.c:30:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 layer.c
In file included from screen.h:144,
                 from layer.c:27:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from layer.c:27:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 sched.c
In file included from screen.h:144,
                 from sched.c:31:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from sched.c:31:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 teln.c
gcc -c -I. -I.    -g -O2 nethack.c
In file included from screen.h:144,
                 from nethack.c:25:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from nethack.c:25:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc -c -I. -I.    -g -O2 encoding.c
In file included from screen.h:144,
                 from encoding.c:27:
display.h:210: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
In file included from screen.h:145,
                 from encoding.c:27:
window.h:249: warning: ‘utmp’ is deprecated (declared at /usr/include/utmp.h:97)
gcc  -o screen screen.o ansi.o fileio.o mark.o misc.o resize.o socket.o search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o termcap.o input.o attacher.o pty.o process.o display.o comm.o kmapdef.o acls.o braille.o braille_tsi.o logfile.o layer.o sched.o teln.o nethack.o encoding.o -lcurses 
14:49 ama-ch% sudo make install                                                                                                                                     [~/screen/src]
Password:
./etc/mkinstalldirs /opt/local/bin `sed < config.h -n -e '/define SCREENENCODINGS/s/^.*"\([^"]*\)"/\1/p'`
cd doc ; make installdirs
./../etc/mkinstalldirs /opt/local/man/man1 /opt/local/info
mkdir /opt/local/info
if [ -f /opt/local/bin/screen-4.0.3 ] && [ ! -f /opt/local/bin/screen-4.0.3.old ]; \
		then mv /opt/local/bin/screen-4.0.3 /opt/local/bin/screen-4.0.3.old; fi
/usr/bin/install -c screen /opt/local/bin/screen-4.0.3
chown root /opt/local/bin/screen-4.0.3 && chmod 4755 /opt/local/bin/screen-4.0.3
if [ -f /opt/local/bin/screen ] && [ ! -f /opt/local/bin/screen.old ]; then mv /opt/local/bin/screen /opt/local/bin/screen.old; fi
rm -f /opt/local/bin/screen
(cd /opt/local/bin && ln -f -s screen-4.0.3 screen)
cp ./utf8encodings/?? `sed < config.h -n -e '/define SCREENENCODINGS/s/^.*"\([^"]*\)"/\1/p'`
cd doc ; make install
./../etc/mkinstalldirs /opt/local/man/man1 /opt/local/info
/usr/bin/install -c -m 644 ./screen.1 /opt/local/man/man1/screen.1
make screen.info
makeinfo ./screen.texinfo -o screen.info
if test -f screen.info; then d=.; else d=.; fi; \
	if test -f $d/screen.info; then \
	for f in $d/screen.info*; do /usr/bin/install -c -m 644 $f /opt/local/info;done; \
	if /bin/sh -c 'install-info --version' >/dev/null 2>&1; then \
	  install-info --info-dir=/opt/local/info $d/screen.info; \
	else true; fi; \
	fi
* Screen: (screen). Full-screen window manager.
install-info(./screen.info): no backup file /var/backups/infodir.bak available.
install-info(./screen.info): no default file /usr/share/base-files/info.dir available, giving up.
make[1]: [install] Error 1 (ignored)
if [ -d /usr/lib/terminfo ]; then \
		PATH="$PATH:/usr/5bin" tic ./terminfo/screeninfo.src; \
		chmod 644 /usr/lib/terminfo/s/screen*; \
	fi
termcap entry (./terminfo/screencap) should be installed manually.
You may also want to install ./etc/etcscreenrc in /opt/local/etc/screenrc

cronで90分おきにコマンドを実行したい

crontabで○分おきにって00-59しか指定できないんですよね!*1
じゃあ90分おきに実行したい場合はどうしよう?と思って、crontabに

*/30  *  *  *  * test $( expr $( date +%s ) % 5400 ) -eq 0 && hoge.zsh

と書いてみたけど動かない。。


しょうがないから、crontabは

*/30  *  *  *  * hoge.zsh

として、90分の判定はhoge.zshで判定することにしました。


hoge.zsh

# 90分ごとにコマンドを実行
DATE=`date "+%Y.%m.%d  %H:%M:%S"`
DATE_SEC=`date +%s`    # 現在のエポック秒(1970.1.1 0:00:00からの経過時間)
DATE_MIN=`expr $DATE_SEC / 60`    # エポック秒を分に変換

if [ `expr $DATE_MIN % 90` -eq 0 ];
then
    echo $DATE >> ~/scripts/hoge.log
    # ここに実行したいコマンド
else
    echo "nonAction.$DATE... $DATE_MIN:$DATE_SEC" >> ~/scripts/hoge.log
fi

こんな感じかなー。cronで30分に1回このスクリプトが実行されて、更にスクリプト内で90分かどうかをチェックします。
最初date +%sを5400秒(90分)で割っていたんだけど、実行時に1秒ほどずれてしまうことが度々あったので、分に変換しています。

*1:正確には、毎時00-59/○分

AppleScriptをコマンドラインから定期的に実行したい

マカーなら1度はAppleScriptのお世話になりますよね!
僕がよく使っているのは、あるアプリケーションを再起動するAppleScriptです。そのアプリケーションはよく不安定になるので、1日に何回も再起動しています。
終了→再起動の2ステップがスクリプト実行の1ステップになって快適・・・なんだけど、スクリプトの実行がめんどくさい!何回も実行するのはめんどくさい!よし、自動化のお勉強をしよう!!!

コマンドラインからAppleScriptを実行

今までLaunchBarとかスクリプトエディタで実行していたけど、自動化するならコマンドラインから実行しないといけません。
シン石丸の電脳芸事ニッキ: コマンドラインからAppleScriptを実行し引数でパラメータを渡す
こちらでその方法が解説されています。

% osascript hoge.scpt

あ、これだけで実行できるんですね。

コマンドのスケジュール実行

やったことないから調べよう><
・・・えーと、cronというものを使うと幸せになれるみたいです。

cronは、UNIX系OSに、装備されている自動実行ツールの一つです。
指定したタイミングで、繰り返し実行されるので、よく使われます。
デフォルトでも、各種ログの、整理を行っています。

http://homepage1.nifty.com/cra/linux/cron.html

素敵な雰囲気がします!
タイミングやコマンドは、crontabというファイルに記述します。
コマンドcrontab -eで現在のユーザーのcrontabをエディタで開くことができます。

% crontab -e    # エディタでcrontabを開く

エディタが開くので、以下のように記述します。

# +------------ 分 (0 - 59)
# | +---------- 時 (0 - 23)
# | | +-------- 日 (1 - 31)
# | | | +------ 月 (1 - 12)
# | | | | +---- 曜日 (0 - 6) (日曜日=0)
# | | | | |
# * * * * * 実行されるコマンド

# 30分おきに以下のシェルスクリプトを実行
*/30  *  *  *  * /Users/ama-ch/scripts/relaunch.zsh

crontab - Wikipedia
crontabの書き方 ― server-memo.net
このあたりを参考にさせていただきました。


30分ごとにrelaunch.zshというスクリプトを実行するようにしました。
relaunch.zshの中身はこんな感じ↓

osascript ~/applescripts/reLaunch.scpt    # あるアプリケーションを再起動するAppleScriptを実行
date "+%Y.%m.%d  %H:%M:%S" > ~/scripts/relaunch.log    # 実行時間をログに吐く

コマンドを2つ実行するだけの簡単なものです。


あとはcrontabを保存して、cronコマンドを実行・・・はしなくて良いみたいです。

% sudo cron                                                                                    [~]
Password:
cron: cron already running, pid: 2341
% ps -p 2341                                                                                   [~]
  PID TTY           TIME CMD
 2341 ??         0:00.03 /usr/sbin/cron

最初からバックグラウンドで動いてるのかな?
crontabに記述したコマンド(relaunch.zsh)がちゃんと実行されているか、ログを監視してみます。

% tail -f ~/scripts/relaunch.log
2009.01.17  12:00:05
2009.01.17  12:30:04
2009.01.17  13:00:03

30分おきに実行されているのがわかりますね!
cronたんが勝手に再起動してくれるようになったので、これからは自分で再起動しなくても良くなりました。やったね!

まとめ

  • AppleScriptはosascriptコマンドで実行できる
  • 自動実行はcronで幸せ
  • 「crontab -e」でエディタを開き、スケジュールとコマンドを記述する
  • 「crontab -l」でcrontabの内容が確認できる

zsh覚え書き

Tabでファイルグロブを展開
ama-ch% echo *~    # ~で終わるファイルを確認
fudemame.py~ maimiku_search.py~ mymixi_diary.py~ output.txt~ search_diary.py~ test.py~ twitter-notifier.py~
ama-ch% rm *~    # ここでTabを押すと・・・
ama-ch% # ↓こうなるので、実行前に対象ファイルが確認できる!
ama-ch% rm fudemame.py~ maimiku_search.py~ mymixi_diary.py~ output.txt~ search_diary.py~ test.py~ twitter-notifier.py~ 
グロビング

参考:UNIX今日の技 - UNIX今日の技/zsh

再帰的にディレクトリを掘るワイルドカード

**で、現在位置より下のディレクトリを再帰的に走査するワイルドカードの指定ができる。
例えばホームディレクトリ以下のどこかにある「new.jpg」というファイルを探す場合、普通は

% find . -name new.jpg -print                                                                  [~]
./python/python-challenge/new.jpg

こんな感じだけど、**を使うと

% ls **/new.jpg                                                                                [~]
python/python-challenge/new.jpg

このように見つけることができる。
さすがにホームディレクトリから再帰的に掘ると時間がかかりますが><

ファイル属性によるグロビング

ワイルドカードに続けて(パターン)を指定することで、マッチする属性を制限できる。

chmod 755 *(/)   # 全てのディレクトリのパーミッションを 755 に
chmod 644 *(^/)  # ディレクトリ以外の全ファイルのパーミッションを 644 に

以下のような指定ができる。

/:ディレクトリ
@:シムリンク
.:通常ファイル
^:否定

*:ディレクトリでない実行権のあるファイル
r:読み込み権のあるファイル
w:書き込み権のあるファイル
x:実行権のあるファイル
R:他人に読み込み権のあるファイル
W:他人に書き込み権のあるファイル
X:他人に実行権のあるファイル
f値:値で指定したアクセス権のファイル
U:自分が所有するファイル
G:自分が所属するグループのファイル
u値:値のユーザが所有するファイル
g値:値のグループが所有するファイル
s:setuidされたファイル
-:次の指定にシンボリックリンクを含む
=:ソケット
p:名前付きパイプ(FIFO)
^:それ以降の指定の否定
拡張グロブ
setopt extended_glob

これを設定すると、以下の拡張グロブが利用できる。

less *.txt~memo.txt    # memo.txt 以外の *.txt にマッチ
rm *~POSCAR*~INCAR~KPOINTS~POTCAR      # vaspの入力ファイル以外の出力ファイルを全て消す
ls ^*.txt      # .txtで終わるファイル以外全て
rm ^(POSCAR*|INCAR|KPOINTS|POTCAR)     # 「rm *~POSCAR*~INCAR~KPOINTS~POTCAR」と等価


ファイルグロブがどのように展開されるかは、Tab以外に以下の方法で確認できる。

C-x g    # ファイルグロブがどう展開されるのか確認
グルーピング
ls *.(sh|txt)   # 拡張子部分が「sh または txt」のもの
ls <10-15>*     # 10〜15の範囲の数字から始まるもの
ls *<->*        # 数字が省略されたら<最小の数-最大の数>でマッチする。この場合は「任意の数字を含むもの」

でm〜nの数が指定できるのかぁ。

連番生成
echo {1..10}  # 「1 2 3 4 5 6 7 8 9 10」に展開
echo {01..10} # 「01 02 03 04 05 06 07 08 09 10」に展開

連番のファイルを作ってみます。

ama-ch% for i in {01..10}                                                                            [~]
for% do
for%    touch number$i
for% done
ama-ch% ls number*                                                                                   [~]
number01 number02 number03 number04 number05 number06 number07 number08 number09 number10

簡単だ!

連続文字列

以下の設定で、アルファベットの展開もできるようになる。

# {a-c} を a b c に展開できるようにする
setopt brace_ccl

実験してみる。

ama-ch% echo {a-c}                                                                                   [~]
a b c
ama-ch% echo {c-a}                                                                                   [~]
a c
ama-ch% echo {a-Z}                                                                                   [~]
Z a
ama-ch% echo {1-3}                                                                                   [~]
1 2 3
ama-ch% echo {a-c1-3}                                                                                [~]
1 2 3 a b c

ふむふむ。

コマンドラインスタック
ESC-q
M-q

と打つと、現在入力中のコマンドを一旦スタックに積み、コマンドラインが消える。そこで新たなコマンドを入力・実行すると、さきほどスタックに積んだコマンドラインが復帰する。

ama-ch% ls /opt/local/bin/    # ここでESC-qを押す
ama-ch% cd ~                  # コマンドラインが消え、新たにコマンドを入力
ama-ch% ls /opt/local/bin/    # さきほどのコマンドが復帰する
manページの呼び出し
ESC-h
M-h

入力中のコマンドについてmanページを表示する。man参照後、コマンドラインが復帰する。


man=jmanとエイリアスを作成すると日本語manが参照できるようになるが、Mac OS Xにはデフォルトでjmanが入っていない。
Mac OS X を UNIX 的に使う - hiroto sakai's site
こちらでjmanとmanページ集をダウンロードしインストールすると、jmanの機能が使えるようになる。manページ集もダウンロードしないと、jmanで参照できるコマンドが全然ありません!
インストールしたら、以下のエイリアスで日本語マニュアルが参照できる。

# 日本語マニュアルを参照(via. http://www.fan.gr.jp/~sakai/unix.php)
alias man=jman
キーバインド

現在のキーバインドの一覧表示は、

ama-ch% bindkey -L

で確認できる。
特定のキーバインド設定を探すなら、こんな感じで。

ama-ch% bindkey -L | grep undo                                                                       [~]
bindkey "^X^U" undo
bindkey "^Xu" undo
bindkey "^_" undo

C-/をundoにしたくて色々調べてみたんだけど、結局分からなかった><

# Emacsライクキーバインド設定
bindkey -e

これでEmacs風のキーバインドになる。さらに以下も追加すると良い感じ。

bindkey "^U" universal-argument

これでEmacs使いならよく使うC-uの機能を使える。

グローバルエイリアス
# グローバルエイリアス
alias -g G='| grep'
alias -g L='| less'
alias -g P='| pbcopy'

設定しているのはこんなもん。最後のpbcopyはMac OS X固有のコマンドで、入力をクリップボードにコピーするコマンド。

補完
# 補完候補を矢印キーで選択
zstyle ':completion:*:default' menu select=1

これを設定しておくと、Tabで表示した補完候補を矢印キーで移動・選択できるようになる。
Tab連打じゃ遠いなという時に便利。

おわり

殴り書きみたいになってしまった><