あけましておめでとうございます。@bussorenre と申します。
2017年の仕事始めなので、自分なりに自分のdotfilesを大掃除した記録を残していきます。
え、多くの人は年末に大掃除するって………?そんなそんなご冗談を…
今までと比較して大きく異る点は以下のあたり。
- emacs の設定ファイルをオレオレel から脱却、spacemacsを使う。
- tmux を使う
- bash → zsh に変更した。したけど、まだzshのメリットを見いだせてない。
なお、これらを整理した結果はgithubにありますので、よかったらどうぞ。参考になるとは言ってない。
emacs 周りの整理
spacemacs に一任
今までオレオレelを使っていたが、「spacemacs神じゃね」と思い、spacemacs をフォーククローンし、自分仕様にカスタマイズしながら使っていく。spacemacs は~/.emacs.d
ディレクトリ以下のファイルを全て管理しており、spacemacs 自体の設定ファイルを~/.spaecemacs に書く事ができる。
spacemacs の導入
https://github.com/syl20bnr/spacemacs を$HOME/.emacs.d/ にクローンする。
# install spacemacs to .emacs.d
# notification - change repository to origin repo or you fork it.
git clone git@github.com:bussorenre/spacemacs.git $HOME/.emacs.d
クローンが完了したら、emacsを起動し、M-x dotspacemacs/install
する。すると、$HOME/.spacemacs
ファイルが自動生成されるので、emacs を再起動し、自分に必要なspacemacs の設定を記述していく。
.spacemacs の設定
spacemacs にはレイヤーという概念があり、(詳細はココを読むこと → http://spacemacs.org/doc/LAYERS.html )コレは何かというと、package.el で管理されるパッケージで、とある事を実現するために必要な複数パッケージを1つの機能としてまとめ直しました。みたいな概念。このレイヤーというのを有効化したりしなかったりで、様々な機能をemacs に追加出来る。
.spacemacs は大きく4つの関数に分かれており、以下の順番で初期化処理が走る。
1. emacs 起動
2. dotspacemacs/init
3. dotspacemacs/user-init
4. dotspacemacs/layers
5. 各レイヤーの初期化処理
6. dotspacemacs/user-config
init には、emacs 全体の初期化処理、user-init には、レイヤーを読み込む際に必要な変数の設定などをすると良いとコメントされている。user-config に、独自のキーコンフィグやオレオレ関数を定義すると良いとされている。
layers の中には有効にするレイヤーなどを記述すれば良い。
利用できるレイヤー一覧はhttp://spacemacs.org/layers/LAYERS.html に列挙されており、無いものは作ればいい。
とりあえず、最低限必要な設定ということで、私は以下のように記述した
(defun dotspacemacs/layers ()
(setq-default
;; 中略
dotspacemacs-configuration-layers
'(
;; emacs-general
helm
gtags
;; language syntax
emacs-lisp
markdown
c-c++
ruby
javascript
html
go
python
;; frameworks
ruby-on-rails
;; os
(osx :variables
osx-use-option-as-meta nil)
;; tools
git
twitter
)
;; 中略
(defun dotspacemacs/init ()
(setq-default
dotspacemacs-editing-style 'emacs
;; 中略
(defun dotspacemacs/user-config ()
;; allocate C-h to backspace
(keyboard-translate ?\C-h ?\C-?)
)
tmux の導入
存在は知っていたものの、上手く使いこなせていなかったので、これを気に使おうと思った。
tmux のconfig は~/.tmux.conf
に記載する。参考記事をパクリスペクトした。この記事で特に面白いと思ったのが、wi-fiとバッテリーの状態をtmux のステータスバーで目視するようにすること。早速コードを見に行って少し改造を加えて完成。
出来たtmux.confが以下の通り。
# prefix キーをC-t に変更する
unbind-key C-b
set-option -g prefix C-t
bind-key C-t send-prefix
# ステータスバーをトップに配置する
set-option -g status-position top
# 左右のステータスバーの長さを決定する
set-option -g status-left-length 90
set-option -g status-right-length 90
# 左側にマシン名:セッション番号など表示
set-option -g status-left '#H:[#P]'
# Wi-Fi、バッテリー残量、現在時刻
# 右側に表示
set-option -g status-right '#(wifi.sh) #(battery.sh) [%Y-%m-%d(%a) %H:%M]'
# センタライズ(主にウィンドウ番号など)
set-option -g status-justify centre
# zsh と同じxterm-256color に設定する
set-option -g default-terminal screen-256color
set -g terminal-overrides 'xterm:colors=256'
# ペインの移動方法を、emacs っぽくする
bind-key C-b select-pane -L
bind-key C-n select-pane -D
bind-key C-p select-pane -U
bind-key C-f select-pane -R
#### COLOUR (Solarized 256)
# default statusbar colors
set-option -g status-bg colour236 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default
# default window title colors
set-window-option -g window-status-fg colour244 #base0
set-window-option -g window-status-bg default
#set-window-option -g window-status-attr dim
# active window title colors
set-window-option -g window-status-current-fg colour166 #orange
set-window-option -g window-status-current-bg default
#set-window-option -g window-status-current-attr bright
# pane border
set-option -g pane-border-fg colour235 #base02
set-option -g pane-active-border-fg colour240 #base01
# message text
set-option -g message-bg colour235 #base02
set-option -g message-fg colour166 #orange
# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange
# clock
set-window-option -g clock-mode-colour colour64 #green
キーポイントは以下の点
- C-tをプレフィクスに。emacs でもそんなに使わないキー。デフォルトのC-bはかなり競合する
- 色設定をzshと同じにしないと、zshとtmux で表示色が違う問題が発生する
zsh 周りの整理
brew install zsh
でzshをインストールした後、chsh -s /bin/zsh
で起動時のシェルをzshに変更する。dotfiles には新しくMacを買った時用にsetup.shというインストールスクリプトが記載されており、そのファイルの末尾にも同様の処理を記述する。
# change shell to zsh
chsh -z /bin/zsh
zsh起動時に自動的にtmuxに入る。
tmux は便利なので、iterm2を起動したら自動的にtmuxが起動している状態にしたい。ということで、参考記事 と同じような事を試しながら以下のスクリプトを書いた
if [[ ! -n $TMUX ]]; then
# get the IDs
ID="`tmux list-sessions`"
if [[ -z "$ID" ]]; then
tmux new-session
fi
ID="`echo $ID | cut -d: -f1`"
tmux attach-session -t "$ID"
fi
コレだと、新しいウィンドウを開けても既存のセッションしか呼び出されず時と場合によって不便だと思うけど、tmux を使いこなそうという戒めを込めてこういう設定に。笑
以上。時間切れなので、今後も、(疲れた時の気晴らしや憑かれた時のお祓いを兼ねて)時間を見つけて改良していく。