Goodbye, World

日々のプログラミングで得た経験を個人的な備忘録としてまとめてます.他のブログ・ページを参考させて頂いている部分が多いので,参考ページへのリンクを併記しております.

tmuxによる複数コンソールの利用

Linuxで作業する際,複数の端末を利用する場面が多々ありますが,端末間でのコピペや他のファイルを参照するための画面分割ができると大変便利です.
そこで,端末を多重化するソフトウェアtmuxをUbuntuに導入してみます.

[参考サイト]:
モテるtmux – 超クールな設定 – まつぼ x Web
tmuxを使い始めたので基本的な機能の使い方とかを整理してみた - 完熟トマト



下記サイトに従い,tmuxと追加情報を表示できるtmux-powerlineの導入を進めていきます.

1.tmuxのインストール

$sudo aptitude install tmux

2.tmux-powerlineのインストール

$cd
$git clone git://github.com/erikw/tmux-powerline.git

3.~/.tmux.confの記述

tmux(とtmux-powerline)の設定を記述する "~/.tmux.conf" には,*1*2を組み合わせたものを利用しました.

下記サイトも参考になると思いますので,好みに合わせて設定を変更して下さい.
達人に学ぶ.tmux.confの基本設定 - Qiita
達人のtmux.confコピペしたら動かなかった話 - 魔法使いの卵

ここまでで

$tmux

とすると,powerlineを伴ったtmuxが起動するかと思います.

tmux-powerlineのアイコン部分が文字化けする場合には,github*3のreadmeのRequirements部に記載されているリンク*4に従い解決して下さい.以下は実際の手順です.

# Download the latest version of the symbol font and fontconfig file.
$wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf
$wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf

# Move the symbol font to a valid font path.
$mkdir ~/.fonts
$mv PowerlineSymbols.otf ~/.fonts/

# Update font cache for the path the font was moved to (root priveleges may be needed to update cache for the system-wide paths).
$fc-cache -vf ~/.fonts/

# Install the fontconfig file. For newer versions of fontconfig the config path is ~/.config/fontconfig/conf.d/, for older versions it’s ~/.fonts.conf.d/ .
$mkdir -p ~/.config/fontconfig/conf.d
$mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/

4.tmuxinatorによるコンソールレイアウトの設定

tmuxでは必要に応じてコンソールの縦分割・横分割が可能ですが,tmuxinatorを利用することでお気に入りのレイアウトを設定ファイルとして保存しておくことが可能です.

tmuxinatorのインストール
# Confirm the version of tmux (version 1.8 and later are recommended.).
$tmux -V

# Confirm the version of gem.
$gem -v

# Install tmuxinator.
$gem install tmuxinator

# Specify EDITOR and SHELL you use.
$echo 'export EDITOR='/usr/bin/vim' >> ~/.bashrc
$echo 'export SHELL='/bin/bash' >> ~/.bashrc

# Copy a bash file for tmuxinator
$wget https://raw.github.com/aziz/tmuxinator/master/completion/tmuxinator.bash
$mkdir ~/.tmuxinator
$mv tmuxinator.bash ~/.tmuxinator/tmuxinator.bash
$echo 'source ~/.tmuxinator/tmuxinator.bash' >> ~/.bashrc

# Make sure everything is set correctly.
$tmuxinator doctor
レイアウトの設定ファイルの作成方法

yml形式でレイアウトをファイルに記述していきます.作成したレイアウトは,次回からのtmuxの起動時に指定できるようになります.

# Create a tmuxinator file according to yml style.
$mux new <filename>

# Launch tmux using the tmuxinator file
$mux start <filename>

上記のリンクにサンプルが公開されていますので,そちらを参考にされると大変勉強になると思います.



5.tmuxの使い方

pane間の作成や移動,上記で紹介したツールの詳細等については下記リンクを参考にして下さい.

tmuxの基本的な使い方とコマンドのまとめ - TASK NOTES
tmux基本のコマンド — nato's memo 1.0 documentation
tmuxの使い方メモ - ヌキのやる気のないエンジニアブログ