1
0

More than 1 year has passed since last update.

tmuxとは

tmux は「ターミナルマルチプレクサ: 一つのスクリーンから別々のプログラムが動作する多数のターミナル (またはウィンドウ) を作成・アクセス・制御することができます。tmux はスクリーンから分離させてバックグラウンドで動作させることができ、後でまた繋ぎ直すことができます。」です。

つまり

  • 画面分割できる
  • sshセッションが切れてjobが停止することが防げる

Installation

brew install tmux

tmux.conf

デフォルトでは、tmux はユーザ毎の設定として ~/.tmux.conf を探します。しかし、~/.config/tmux/tmux.conf も使用可能です (このパスはハードコードされていて、$XDG_CONFIG_HOME は無視されます)。グローバルな設定ファイルは /etc/tmux.conf を使用できます。しかし、デフォルトでは Arch のパッケージはこのファイルを同梱していません。

tmux.confとはtmuxの設定ファイルのことで、.tmux.confと書く人もいます。
設定ファイルの置く場所は

~/.tmux.conf

or

~/.config/tmux/tmux.conf

です。

可能な限りホームディレクトリを綺麗にして置きたいので私は後者に配置してます。


#################################################
#
#  BASIC Setting
#

#  256 色端末を使用する
set -g default-terminal 'screen-256color'
set -g terminal-overrides 'xterm:colors=256'

#
#  Prefix キーを Ctrl-b から Ctrl-j に変更
#
set -g prefix C-j
unbind C-b

set -g base-index 1         # ウィンドウの番号を 1 から開始
setw -g pane-base-index 1   # ペインの番号を 1 から開始

set-option -g renumber-windows on   # ウィンドウを閉じた時に番号を詰める

set -s escape-time 0
set-option -g mouse on

# message表示時のstatus lineの色。dispaly,confirm-before -p などのコマンド出力の色
set -g message-style fg=colour68,reverse,bg=brightwhite

# paneを区切っている線の色
set -g pane-active-border-style fg=colour111,bg=colour236
set -g pane-border-style fg=colour111,bg=colour236

#################################################
#
#  KEY BINDING Setting
#

#  Prefix + vim のキーバインドでペインを移動する
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R

#  Prefix + vim のキーバインドでペインをリサイズする
bind -r H resize-pane -L 5
bind -r J resize-pane -D
bind -r K resize-pane -U
bind -r L resize-pane -R 5

#  vimのコピーを適用
setw -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'C-v' send -X rectangle-toggle
bind-key -T copy-mode-vi 'y' send -X copy-selection

#  Ctrl-o でペインをローテーションしながら移動
bind -n C-o select-pane -t :.+

bind -r C-h select-window -t :-     # Prefix + Ctrl-h でウィンドウ切り替え
bind -r C-l select-window -t :+     # Prefix + Ctrl-l でウィンドウ切り替え

bind | split-window -h -c '#{pane_current_path}'    # Prefix + | でペインを垂直分割する
bind - split-window -v -c '#{pane_current_path}'    # Prefix + - でペインを水平分割する


# 設定ファイルをリロード
bind-key -T prefix r source-file ~/.config/tmux/tmux.conf \; display-message 'Reloard was successful.'

# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

#################################################
#
#  STATUS BAR Setting
#

set-option -g status-position top       # ステータスバーをトップに配置する
set -g status-interval 1                # ステータスバー更新速度 15s(default) → 1s

#  Length
set -g status-left-length 90
set -g status-right-length 90

#  Contents
set -g status-fg 'brightwhite'  # ForeGround_Color
set -g status-bg 'colour238'    # BackGround_Color

#  left:マシン名[ペイン番号]
set -g status-left '#[fg=brightwhite, bg=colour111, bold] #S #[fg=colour111, bg=colour238]'

#  right: バッテリー情報 ipaddress tmuxインジケーター
set -g status-right '#{prefix_highlight}#[fg=colour111, bg=colour238]#[fg=brightwhite, bg=colour111, bold] #{battery_percentage}%#[fg=colour238, bg=colour111] #[fg=colour111, bg=colour238]#[fg=brightwhite, bg=colour111, bold]#(~/.config/tmux/.tmux/bin/gip)#[fg=colour238, bg=colour111] #[fg=colour111, bg=colour238]#[fg=brightwhite, bg=colour111]#(~/.config/tmux/.tmux/bin/print_ip) '

# Window Status
setw -g window-status-separator "" # window間の隙間を排除
set-option -g status-justify 'left'   # window-status を左寄せ
# 非アクティブウィンドウ
setw -g window-status-format '#[fg=colour238, bg=brightblack]#[fg=brightwhite, bg=brightblack, bold] #W #[fg=brightblack, bg=colour238]'
# アクティブウィンドウ
setw -g window-status-current-format '#[fg=colour238, bg=colour68]#[fg=brightwhite, bg=colour68, bold] #W #[fg=colour68, bg=colour238]'

#################################################
#
#  PANE Setting
#

#  ベーシックペイン
set -g window-style 'fg=white, bg=colour240'

#  アクティブペイン
set -g window-active-style 'fg=white, bg=colour236'

#################################################
#
#  PLUGIN Setting
#

# Key bindings
# prefix + I: Installs new plugins from GitHub or any other git repository
# prefix + U: updates plugin(s)
# prefix + option + u: remove/uninstall plugins not on the plugin list

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-battery'  # https://github.com/tmux-plugins/tmux-battery
#set -g @plugin 'tmux-plugins/tmux-online-status'  # https://github.com/tmux-plugins/tmux-online-status
# set -g @plugin 'tmux-plugins/tmux-sidebar' # https://github.com/tmux-plugins/tmux-sidebar
set -g @plugin 'tmux-plugins/tmux-resurrect' # https://github.com/tmux-plugins/tmux-resurrect
set -g @plugin 'tmux-plugins/tmux-continuum' # https://github.com/tmux-plugins/tmux-continuum

set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @prefix_highlight_fg 'colour111'
set -g @prefix_highlight_bg 'colour238'

# https://github.com/tmux-plugins/tpm
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.config/tmux/.tmux/plugins/tpm/tpm'

使用しているフォントはhack-nerd-fontです。
hack-nerd-fontのインストール方法は下記です。

brew tap homebrew/cask-fonts
brew install font-hack-nerd-font

下記コマンドでtmuxを起動

tmux
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0