Λάδι Βιώσας

http://profile.hatena.ne.jp/kenkitii/

MeadowとTortoiseSVNでスクリプト書きWindows環境を作る(さくらサーバー編)

最近、なんだか時間がなくて、趣味プログラミング用の Macbook を持ち運ばなくなってしまいました。しかし、手元に Macbook がない時に限ってスクリプトを書きたくなるもので、今まで悶々としていたんですが、重い腰をあげて仕事場のWindowsマシンにスクリプト書き用開発環境を作ってみましたんで、その手順メモ。あ、さくらのレンタルサーバー上にsubversionリポジトリがあることを前提にしてます。ご了承ください。

Meadow3のインストール

ココから、Netinstall packages の setup-ja.exe をダウンロード&インストールします。で、環境変数HOMEを、Windows上のホームフォルダに設定し、Meadowのショートカットの作業フォルダを%HOME%に変更します。

次に、emacsを使う上で anything.el がないと生きていけない体になってしまっているので anything.el を入れておきます。anything.elanything-config.elをダウンロードして、meadowインストールフォルダにあるsite-lispフォルダ(ロードパスの通ったところ)に置きます。で、%HOME%の場所にこんな感じで.emacs を作成。

;;;; -*- mode: emacs-lisp; coding: iso-2022-7bit -*-
;;;;
;;;; Copyright (C) 2001 The Meadow Team

;; Author: Koichiro Ohba <koichiro@meadowy.org>
;;      Kyotaro HORIGUCHI <horiguti@meadowy.org>
;;      Hideyuki SHIRAI <shirai@meadowy.org>
;;      KOSEKI Yoshinori <kose@meadowy.org>
;;      and The Meadow Team.


;; ;;; Mule-UCS の設定
;; ;; ftp://ftp.m17n.org/pub/mule/Mule-UCS/ が オフィシャルサイトですが、
;; ;; http://www.meadowy.org/~shirai/elisp/mule-ucs.tar.gz に既知のパッチ
;; ;; をすべて適用したものがおいてあります。
;; ;; (set-language-environment) の前に設定します
;; (require 'jisx0213)


;; 日本語環境設定
(set-language-environment "Japanese")


;; IMEの設定
(mw32-ime-initialize)
(setq default-input-method "MW32-IME")
(setq-default mw32-ime-mode-line-state-indicator "[--]")
(setq mw32-ime-mode-line-state-indicator-list '("[--]" "[あ]" "[--]"))
(add-hook 'mw32-ime-on-hook
	  (function (lambda () (set-cursor-height 2))))
(add-hook 'mw32-ime-off-hook
	  (function (lambda () (set-cursor-height 4))))

;; マウスカーソルを消す設定
(setq w32-hide-mouse-on-key t)
(setq w32-hide-mouse-timeout 5000)

;; font-lockの設定
(global-font-lock-mode t)

;; 初期フレームの設定
(setq default-frame-alist
      (append (list '(foreground-color . "black")
		    '(background-color . "LemonChiffon")
		    '(background-color . "gray")
		    '(border-color . "black")
		    '(mouse-color . "white")
		    '(cursor-color . "black")
;;		    '(ime-font . (w32-logfont "MS ゴシック"
;;					      0 16 400 0 nil nil nil
;;					      128 1 3 49)) ; TrueType のみ
;;		    '(font . "bdf-fontset")    ; BDF
;;		    '(font . "private-fontset"); TrueType
		    '(width . 80)
		    '(height . 40)
		    '(top . 100)
		    '(left . 100))
	      default-frame-alist))



;; Ctrl-h をバックスペースに
(global-set-key "\C-h" 'delete-backward-char)

;; 画面をページアップ、ページダウンするときにカーソルを固定
(setq scroll-preserve-screen-position t)

;; Shift + 矢印キーで範囲選択
;; 選択範囲に色をつける
(transient-mark-mode 1)

;; font-lock モード(文字の色付け)
(global-font-lock-mode t)

;; 対応する括弧のハイライト
(show-paren-mode 1) 

;; ツールバーを消す
(tool-bar-mode 0)

;; バックアップなし
(setq backup-inhibited t)
(setq make-backup-files nil)

;; インデント時にタブを使わないでスペースを使う
(setq-default tab-width 4 indent-tabs-mode nil)

;; タブ幅を 4 に設定
(setq-default tab-width 4)

;; 起動画面を消す
(setq inhibit-startup-message t)

;; anything
(require 'anything-config)
(define-key anything-map "\C-p" 'anything-previous-line)
(define-key anything-map "\C-n" 'anything-next-line)
(define-key anything-map "\C-v" 'anything-next-page)
(define-key anything-map "\M-v" 'anything-previous-page)
(global-set-key [?\C-;] 'anything)

;; 起動時のディレクトリをホームに
(cd "~")

;; ;;; shell の設定

;; ;;; Cygwin の bash を使う場合
;; (setq explicit-shell-file-name "bash")
;; (setq shell-file-name "sh")
;; (setq shell-command-switch "-c") 

;; ;;; Virtually UN*X!にある tcsh.exe を使う場合
;; (setq explicit-shell-file-name "tcsh.exe") 
;; (setq shell-file-name "tcsh.exe") 
;; (setq shell-command-switch "-c") 

;; ;;; WindowsNT に付属の CMD.EXE を使う場合。
;; (setq explicit-shell-file-name "CMD.EXE") 
;; (setq shell-file-name "CMD.EXE") 
;; (setq shell-command-switch "\\/c") 

;; argument-editing の設定
(require 'mw32script)
(mw32script-init)

;; ;;; browse-url の設定
;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)

;; ;;; 印刷の設定
;; ;; この設定で M-x print-buffer RET などでの印刷ができるようになります
;; ;;
;; ;;  notepad に与えるパラメータの形式の設定
;; (define-process-argument-editing "notepad"
;;   (lambda (x) (general-process-argument-editing-function x nil t)))
;;
;; (defun w32-print-region (start end
;; 				  &optional lpr-prog delete-text buf display
;; 				  &rest rest)
;;   (interactive)
;;   (let ((tmpfile (convert-standard-filename (buffer-name)))
;; 	   (w32-start-process-show-window t)
;; 	   ;; もし、dos 窓が見えていやな人は上記の `t' を `nil' にします
;; 	   ;; ただし、`nil' にすると Meadow が固まる環境もあるかもしれません
;; 	   (coding-system-for-write w32-system-coding-system))
;;     (while (string-match "[/\\]" tmpfile)
;; 	 (setq tmpfile (replace-match "_" t nil tmpfile)))
;;     (setq tmpfile (expand-file-name (concat "_" tmpfile "_")
;; 				       temporary-file-directory))
;;     (write-region start end tmpfile nil 'nomsg)
;;     (call-process "notepad" nil nil nil "/p" tmpfile)
;;     (and (file-readable-p tmpfile) (file-writable-p tmpfile)
;; 	    (delete-file tmpfile))))
;; 
;; (setq print-region-function 'w32-print-region)

;; ;;; fakecygpty の設定
;; ;; この設定で cygwin の仮想端末を要求するプログラムを Meadow から
;; ;; 扱えるようになります
;; (setq mw32-process-wrapper-alist
;;       '(("/\\(bash\\|tcsh\\|svn\\|ssh\\|gpg[esvk]?\\)\\.exe" .
;; 	  (nil . ("fakecygpty.exe" . set-process-connection-type-pty)))))

;;;
;;; end of file
;;;

うちの環境だけかもしれませんが、anything.elを使おうとすると、w3m.exeがないよって怒られたので、ココからダウンロードして、meadow/binフォルダに入れときました。

Putty のインストール

Puttyごった煮版をココからダウンロードしてインストールします。そしたらインストールフォルダにある、puttygen.exe を起動し、秘密鍵を作ります。[Generate]ボタンを押して、[Please generate som randomness by moving the mouse over the blank area.]と書いてある辺りで、マウスをぐりぐりします。キーが作成されると、パスフレーズ入力するボックスが出てくるのでパスフレーズを決めます。出来たキーは、[Save private key]ボタンを押して、ホームディレクトリ等(無くさない様に!)に保存します。

[Public key for pasting into OpenSSH authorized_keys file:] を選択後コピペして subversionリポジトリを置いてあるサーバーの ~/.ssh/authorized_keysに貼り付けます。

で、次にPuttyインストールフォルダにある Pageant.exe(←ssh-agentね)を起動しタスクトレイに「帽子かぶったコンピュータのアイコン」がでたら(↓この画像の真ん中のやつ)

ダブルクリックし、[AddKey]ボタンを押し、先程作った秘密鍵を読み込みます。パスフレーズを聞かれるので、さっき決めたパスフレーズを入力します。

以上で、Pageant(ssh-agent) を使って、パスワードなしにサーバーログイン出来るようになりました。起動時に1回だけパスフレーズを入力する必要がありますけどね。無事ログイン出来たら Pageant.exe のショートカットをスタートアップフォルダにぶちこんでおきます。

TortoiseSVN

次に、TortoiseSVNココからダウンロード&インストール&再起動。で、チェックアウトする作業フォルダ作って右クリックして、[SVN Checkout...]します。
[URL of repository:]のところに、

svn+ssh://your_account@your_account.sakura.ne.jp/home/your_account/var/svn/repo

てな感じで入力します。your_accountのところはご自分のさくらアカウントに置き換えてくださいね。

まとめ&おまけ

ふう、、つかれた。まったくもってWindowsはめんどうくさいなあ、、、で、あれこれランチャー探してて、OSXで昔はやったQuicksilverみたいなのないかなーと思ったらいいのを見つけました。Launchyってやつ。
http://www.launchy.net/images/amarok.png
↑Alt+Spaceでこんなん出てきてイカしてます。うーん便利。