Skip to content

Instantly share code, notes, and snippets.

@odd-poet
Last active October 3, 2020 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odd-poet/a695949931d3e1816377a752baf38361 to your computer and use it in GitHub Desktop.
Save odd-poet/a695949931d3e1816377a752baf38361 to your computer and use it in GitHub Desktop.
tmux 설정.
# 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-window-option -g pane-base-index 1
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
setw -g mode-keys vi
setw -g 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
# 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]'

tmate plugin

tmate oh-my-zsh plugin.

tmatetmux를 fork한 툴로 tmux 세션 공유를 쉽게 도와주는 툴이다. (tmuxtmate는 동시에 설치되어 있어도 무방하단다)

features

tmate-S 옵션으로 socketfile을 직접 지정하여 사용하는 것을 권하는데, 이 플러그인은 session 이름으로 socketfile을 생성하고 관리해주며 session에 대한 자동완성을 지원한다. (tmate는 하나의 socket에 다수의 session을 생성하는 것을 지원하지 않는다.)

  • tmnew
    • 세션 생성
  • tma
    • 세션 attach
  • tmkill
    • 세션 kill
  • tmls
    • 세션 목록
  • tmshare
    • 세션 공유에 필요한 접속정보를 출력한다.
  • tm_socket : (디버그용)
    • 세션에 대한 socket 파일 출력.

install

oh-my-zshtmate를 설치한 후에 아래와 같이 설치.

git clone git@github.com:odd-poet/tmate-zsh-plugin.git ~/.oh-my-zsh/plugins/tmate
#################
# TMate plugin
# @author: oddpoet@gmail.com
#
# tmate(https://tmate.io/) is a fork of tmux.
# This plugin manages socketfile for session and provides auto-completion.
#
# note: tmate doesn't support multiple-session, so it create a session per socketfile.
#------
if which tmate &> /dev/null
then
local SOCKET_PATH=/tmp/tmate-501
mkdir -p $SOCKET_PATH
# socket file path
function tm_socket() {
echo $SOCKET_PATH/$1
}
# create session
function tmnew() {
local session=$1
if [[ "$session" == "" ]];then
print "usage: tmnew session_name"
print " (create new session)"
return 1
fi
# check socketfile
local socket_file=$(tm_socket $session)
if [ -S $socket_file ];then
print "sokect file already exists: $socket_file"
return 1
fi
tmate -S $socket_file new-session -d
tmate -S $socket_file wait tmate-ready
tmate -S $socket_file rename-session -t 0 $session
print "created tmux session : $session"
print "you could attach this session like blow :"
print " tma $session"
print
}
# kill session
function tmkill() {
local session=$1
if [[ "$session" == "" ]];then
print "usage: tmkill session_name"
print " (kill given session)"
return 1
fi
local socket_file=$(tm_socket $session)
if [ ! -S $socket_file ];then
print "session NOT exists : $session"
print
return 1
fi
tmate -S $socket_file kill-server
print "killed tmux session : $session"
}
# list sessions
function tmls() {
ls $SOCKET_PATH | sed 's/.sock$//g'
}
# attach session
function tma() {
local session=$1
if [[ "$session" == "" ]];then
print "usage: tma session_name"
print " (attach given session)"
return 1
fi
local socket_file=$(tm_socket $session)
if [ ! -S $socket_file ];then
print "session NOT exists : $session"
print
return 1
fi
# get actual session name. (session name could be changed by user.)
print "attaching tmux session : $session"
local session=`tmate -S $socket_file ls | awk -F : '{print $1}'`
tmate -S $socket_file a -t $session
}
# print session info to share
function tmshare() {
local session=$1
if [[ "$session" != "" ]];then
local socket_file=$(tm_socket $session)
if [ ! -S $socket_file ];then
print "session NOT exists : $session"
print
return 1
fi
print "tmux session: $1"
print "* read-only"
tmate -S $socket_file display -p ' #{tmate_ssh_ro}'
tmate -S $socket_file display -p ' #{tmate_web_ro}'
print "* read-write"
tmate -S $socket_file display -p ' #{tmate_ssh}'
tmate -S $socket_file display -p ' #{tmate_web}'
elif [[ "$TMUX" != "" ]]; then
print "current shell on tmux session: "
print "* read-only"
tmate display -p ' #{tmate_ssh_ro}'
tmate display -p ' #{tmate_web_ro}'
print "* read-write"
tmate display -p ' #{tmate_ssh}'
tmate display -p ' #{tmate_web}'
else
print "usage: tmshare session_name"
print " (print session info to share)"
fi
}
function _tm_list_session() {
_arguments "1: :($(tmls))"
}
compdef _tm_list_session tma
compdef _tm_list_session tmkill
compdef _tm_list_session tmshare
# alias
else
print "zsh tmate plugin: tmate not found. Please install tmate before using this plugin."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment