はじめてのtmuxからTmuxinator導入まで
プロジェクトを閉じて開いてをもっと効率よくしたい!ってことでtmuxinatorをインストールして使い始めるまでを書いてみました。tmux,tmu-powerline,tmuxinatorまで一通りそろってインストールするドキュメントが無くて手間取ったのでまとめておきました。
目次
- tmuxのインストール
- tmux-powerlineのインストール
- tmuxinatorのインストール
1. tmuxのインストール
まずは最初にtmuxをhomebrewからインストールします
brew install tmux
設定ファイルを生成して、設定を追加します。
vim ~/.tmux.conf
#------------------------------------- # キーバインド設定 #------------------------------------- # prefixのキーバインドを変更 unbind-key C-b set -g prefix C-t # ~/.tmux.confの読み込みキーバインド unbind r bind r source-file ~/.tmux.conf \; display-message "tmux RELOADED!!" # tmuxセッションをkillする時に下部に確認ダイアログを表示する unbind K bind K confirm-before "kill-window" #------------------------------------- # 基本設定 #------------------------------------- set -g default-shell /bin/bash set -g status on set -g status-interval 2 set -g status-utf8 on set -g status-justify "left" set -g status-left-length 100 set -g status-right-length 120 # スクロール設定 set-window-option -g mode-mouse on # コピー set -g mode-mouse on set -g mouse-resize-pane on set -g mouse-select-pane on set -g mouse-select-window on
2. tmux-powerlineのインストール
tmux-powerlineのインストール
git clone https://github.com/erikw/tmux-powerline.git ~/.tmux-powerline
設定ファイルを生成する。
cd .tmux-powerline/ ./generate_rc.sh mv ~/.tmux-powerlinerc.default ~/.tmux-powerlinerc
天気を表示するように設定
下記部分にyahoo.comの天気ページのURLの一番右の数字を入れる 例)http://weather.yahoo.com/japan/tokyo-prefecture/tokyo-26237038/ -> 26237038
export TMUX_POWERLINE_SEG_WEATHER_LOCATION=""
~/.tmux.confにpowerlineの設定を追加する 先ほどの.tmux.confに追加していきます。
#------------------------------------- # 色設定 # カラーコードは以下コマンドで確認 # ~/.tmux-powerline/color_palette.sh #------------------------------------- # pane-active-border set -g pane-active-border-fg black set -g pane-active-border-bg cyan #------------------------------------- # tmux-powerline #------------------------------------- set -g status-left "#(~/.tmux-powerline/powerline.sh left)" set -g status-right "#(~/.tmux-powerline/powerline.sh right)" set-window-option -g window-status-current-format "#[fg=colour235, bg=colour 27]⮀#[fg=colour255, bg=colour27] #I ⮁ #W #[fg=colour27, bg=colour235]⮀"
ここで、一度tmuxを起動させてみます
tmux
すると、文字化けしているのがわかると思います(下部ステータスバー) こちらを修正するためにフォントを変更しなければいけません
フォントの追加(Ritcy)
powerlineで使用するフォントを合成する必要があります。 そのために、Ritcyフォントを使用してフォントを作成して行きましょう。
まず、フォントの合成に必要になるfontforgeを落としてきます
brew install fontforge
作業用のディレクトリを作ってその中で作業して行きます
cd tmp
始めにこちらからから Migu M1フォントをダウンロードしてきます。 うまくコマンドラインからダウンロード出来なかったのでちょっとあれですがブラウザから落としてきます。 後は以下のコマンドを実行して行けばフォントを合成出来るはずです。(migu-m1のバージョン名は要確認)
git clone https://github.com/yascentur/Ricty.git cd Ricty wget http://levien.com/type/myfonts/Inconsolata.otf mv ~/Downloads/migu-m1-20130617.zip . unzip migu-m1-20130617.zip mv ./migu-1m-20130617/migu-1m-bold.ttf . mv ./migu-1m-20130617/migu-1m-regular.ttf . sh ricty_generator.sh auto
これで、Ritcyフォントが合成完了しました。 これをフォントとしてMacで使えるようにします
mv Ricty-*.ttf ~/Library/Fonts/
さて、この次に、Rictyをベースとしてpowerline用のフォントを合成します。 これには、以下のスクリプトを実行するだけです。
git clone https://github.com/Lokaltog/vim-powerline.git vim-powerline fontforge -script ./vim-powerline/fontpatcher/fontpatcher ~/Library/Fonts/Ricty-Bold.ttf
これで、powerline用のフォントが現在ディレクトリに合成されました。 これをまた、Macで使えるようにします。
mv Ricty-Bold-Powerline.ttf ~/Library/Fonts/
3.tmuxinatorのインストール
gem install tmuxinator echo ' [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator ' >> ${HOME}/.bashrc source ${HOME}/.bashrc
でインストール完了
tmuxinatorは環境変数 $EDITOR と $SHELL を参照するので、設定してない場合は設定する。
echo 'export EDITOR=/usr/bin/vim' >> ${HOME}/.bashrc
echo 'export SHELL=/bin/bash' >> ${HOME}/.bashrc
tmuxinatorが使用可能かどうかチェックを行う
tmuxnator doctor
これで、すべてYesになっていれば完了!
tmuxinatorの設定方法
mux new <projectname>
で新規プロジェクト用の設定ファイル生成。ymlで記述して行くようです。
# ~/.tmuxinator/xhistory.yml name: projectname root: ~/develope/rails_projects/xhistory/server/xhistory # Optional tmux socket socket_name: projectname # Runs before everything. Use it to start daemons etc. # pre: sudo /etc/rc.d/mysqld start # Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions. # pre_window: rbenv shell 2.0.0-p247 # Pass command line options to tmux. Useful for specifying a different tmux.conf. # tmux_options: -f ~/.tmux.mac.conf # Change the command to call tmux. This can be used by derivatives/wrappers like byobu. # tmux_command: byobu windows: - editor: layout: main-vertical panes: - subl . - bundle exec guard - bundle exec spring rails s - server: ssh remote.net
mux start <projectname>
でtmuxinatorを実行。設定ファイルで設定した通りに起動します。
参考サイト
- tmux, tmux-powerline, font周りについて
- tmuxinatorについて