tmux 사용 방법 정리

2019. 8. 11. 13:23꿀팁 분석 환경 설정/Linux 관련 팁

728x90

창을 여러개를 띄워서 사용할 일이 있다.

 

좋은 방법으로 tmux를  알고있었지만, 배우기 귀찮아서 안했다.

 

그런데 커피숍 와이파이를 쓰다가 여러개를 띄울때 한개라도 비활성화가 되면 안되는데 꺼지는 경우가 생겼다.

 

와이파이 문제인지는 모르겠지만 암튼 관리하기도 용이한 것 같아서 사용하면서 찾아보고 정리했다.

 

사용법은 간단했다.

 

일단 1. CTRL + B 를 누르고 

그리고 오른쪽에 있는 것을 눌러주면 되는데,

% 같은 것을 처음아 다 같이 눌러야하는줄 알고ㅎㅎㅎㅎ 굉장히 해맸는데.

일단 CTRL+B 를 누른 다음에 SHIFT + 5( = %)를 눌러주는 식으로 하면 된다 ㅎㅎㅎ

PREFIX = <CTRL-B> (기본이 저렇게 설정됨)
## 실행
tmux
## 창 열로 분할
<CTRL-B> %
## 창 행으로 분할
<CTRL-B> "

## 창 이동
<CTRL-B> 화살표키

## 창 세트 하나 더 만들기
<CTRL-B> c

## 창끼리 이동 (하단에 번호 확인)
<CTRL-B> 0
<CTRL-B> 1

## detach 하는 방법 (안에것은 돌아가게 유지가능)
<CTRL-B> d 

## detach하고 나서 확인
tmux ls
## 다시 접속
tmux attach

## 종료하기
1. detach 후에 모두 킬하기(한번에 하기)
<CTRL-B> d 
tmux kill-session -t 0

2. 개별적으로
<CTRL-B> x (pane 종료) 
<CTRL-B> & (window 종료)

## session에 이름 할당하기 (관리 편안)
tmux new-session -s SESSION_NAME
tmux list-sessions: 현재 열려있는 세션 목록을 보여준다.
tmux has-session -t TARGET_SESSION: TARGET_SESSION이라는 이름의 세션이 열려있는지 확인해본다.
tmux attach-session -t TARGET_SESSION: TARGET_SESSION이라는 이름의 세션으로 들어간다.


## 창 사이즈 동일하기 해주기!!!( 유용 )
열로 동일하게
select-layout even-vertical
<Ctrl-B> Alt+2

행으로 동일하게
select-layout even-horizontal
<Ctrl-B> Alt+1

## autoresize
<Ctrl-B> Space

## 시간 보여주기
<Ctrl-B> t

## pane 순서 변경하기! (switch)
<Ctrl-B> <Ctrl-o> (시계 반대)
<Ctrl-B> <Alt-o> (시계 방향)

추가적으로 좋은 명령어

## aaa 라는 session을 만들고 바로 detach 하기 
tmux new -s aaa -d
## attach 간단하게 하기 
tmux attach -t aaa
tmux a -t aaa
## kill all session
tmux kill-server
## show pane number
ctrl+b q
## kill pane
ctrl+b x
## 모든 session 똑같이 작동시키기
ctrl + b
:setw synchronize-panes 
## 모든 session 똑같이 작동시키는 것 종료하기
ctrl + b
:setw synchronize-panes off

tmux conf 파일 없으면 만드는 방법 (아래 링크 참고)

1. tmux.conf 파일을 만들기

vi  ~/.tmux.conf
# 0 is too far from ` 😉
set -g base-index 1

# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on

#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000

setw -g mode-keys vi
setw -g mode-mouse on
setw -g monitor-activity on

bind-key v split-window -h
bind-key s split-window -v

bind-key J resize-pane -D 5
bind-key K resize-pane -U 5
bind-key H resize-pane -L 5
bind-key L resize-pane -R 5

bind-key M-j resize-pane -D
bind-key M-k resize-pane -U
bind-key M-h resize-pane -L
bind-key M-l resize-pane -R

# Vim style pane selection
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# 위에 synchronize-panes 을 (ctrl + B y)라는 옵션으로 사용할 수 있게 함.
bind-key y set-window-option synchronize-panes



# Use Alt-vim keys without prefix key to switch panes
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# Use Alt-arrow keys without prefix key to switch panes
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

# Shift arrow to switch windows
bind -n S-Left  previous-window
bind -n S-Right next-window

# No delay for escape key press
set -sg escape-time 0

# Reload tmux config
bind r source-file ~/.tmux.conf

# THEME
set -g status-bg black
set -g status-fg white
set -g window-status-current-bg white
set -g window-status-current-fg black
set -g window-status-current-attr bold
set -g status-interval 60
set -g status-left-length 30
set -g status-left '#[fg=green](#S) #(whoami)'
set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=white]%H:%M#[default]'

2. 적용하기

위에 파일을 저장하고나서 적용을 해보자

이미 만들어져있다면 누군가 해놓은 거니 다 지우지 말고 옵션만 추가로 저장을 하자.

tmux source-file ~/.tmux.conf

3. 변경된 점 확인하기

아래와 같이 before에서 길었던 것이 after 처럼 간편하기 할 수 있게 된다.

## before 
ctrl + b
:setw synchronize-panes 


--> 
## after
ctrl + b 
y

 

아래 사이트에서 발견한 tmux.conf  공유

참고하면 좋을 것 같다.

set-option -g default-command "tmux-shell-wrapper"

# Make shift+arrows, ctrl+arrows etc work in Vim.
set -g xterm-keys on

# See if this fixes slow ESC issues.
# http://unix.stackexchange.com/questions/23138/esc-key-causes-a-small-delay-in-terminal-due-to-its-alt-behavior
set -s escape-time 0

# Start window and pane indices at 1.
set -g base-index 1
set -g pane-base-index 1

# Status bar styling and content.
set -g status-bg black
set -g status-fg white
set -g status-left '#S '

# Show keyboard layout in prompt, assuming some script writes it to that path;
# it's "/User/…" instead of "~" so VMs can read from their symlinked OS X host home directory.
set -g status-right '#(cat /Users/$USER/.keyboard_layout 2> /dev/null) | #22T | %H:%M %d-%b-%y'
set -g status-right-length 60
set -g status-interval 2

# Highlight the active window in the status bar.
set-window-option -g window-status-current-bg yellow
set-window-option -g window-status-current-fg black

# Don't prompt to kill panes/windows.
bind-key x kill-pane
bind-key & kill-window

# Cycle panes.
bind b select-pane -t :.+
bind C-b select-pane -t :.+

# More intuitive split-window mappings.
bind "'" split-window -h
bind - split-window -v

# Maximize pane, e.g. for copying.
bind-key z resize-pane -Z

# Switch pane and zoom
# https://twitter.com/tskogberg/status/792025881573199872
bind C-z select-pane -t :.+ \; resize-pane -Z

# Reload tmux conf.
unbind r
bind r source-file ~/.tmux.conf\; display "Reloaded conf."

# http://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future

# Use vim keybindings in copy mode
setw -g mode-keys vi

# Unbork my iTerm ctrl+1 etc mappings in tmux 2.1
# https://github.com/tmux/tmux/issues/159
set -g assume-paste-time 0

 

 

 

 

junho85.pe.kr/320

 

 

unix.stackexchange.com/questions/294956/how-do-i-get-a-default-tmux-configuration-file

 

How do I get a default tmux configuration file?

I installed tmux via apt-get and there is no .tmux.conf file in my home directory, even after I run tmux. I have been trying to follow a tmux tutorial, but the first part involves modifying this f...

unix.stackexchange.com

https://gist.github.com/henrik/1967800

 

tmux cheatsheet

tmux cheatsheet. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

ostechnix.com/tmux-command-examples-to-manage-multiple-terminal-sessions/

 

Tmux Command Examples To Manage Multiple Terminal Sessions

Tmux is free, open source and cross-platform Terminal multiplexer. In this guide, we will discuss most-commonly used Tmux commands in Linux.

ostechnix.com

 

728x90