美文网首页
最简单最省事儿的方式上手用tmux

最简单最省事儿的方式上手用tmux

作者: leapking | 来源:发表于2018-03-09 14:49 被阅读14次

tmux (https://github.com/tmux/tmux/wiki)

快捷方式

纵向切分窗口: ctrl+j+%
横向切分窗口: ctrl+j+"

新建窗口:ctrl+j+n
关闭窗口:ctrl+j+x
重命名窗口:ctrl+j+,
最大化窗口:ctrl+j+z
切换窗口:shift+方向键

切换窗格:ctrl+j+方向键
调整窗格大小:ctrl+j+ctrl+方向键

复制模式:ctrl+j+[

自动化脚本

安装完tmux后,无需任何配置。每次执行这个脚本启动tmux即可。

#!/bin/sh
#
# name     : tmux.sh, make tmux easy
# author   : leapking leapking@126.com
# license  : GPL
# created  : 2015 May 12
# modified : 2017 Nov 08
#

CMD=$(which tmux) # get tmux path
if [ -z $CMD ]; then
    echo "You need to install tmux."
    exit 1
fi

###
### Check Config ###
if [ ! -f /etc/tmux.conf -a ! -f ~/.tmux.conf ]; then
cat <<-EOF >~/.tmux.conf
# Easy config reload
bind r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded ..."

# Send prefix
set -g prefix C-j
unbind C-b

# Switch windows use Shift+Arrow key
bind -n S-Left  previous-window
bind -n S-Right next-window

# Switch panes use Alt+Arrow key
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

# While split or create window turn to old path
bind '%' split-window -h -c '#{pane_current_path}'
bind '"' split-window -v -c '#{pane_current_path}'
bind 'c'   new-window    -c '#{pane_current_path}'

# Window index and size
set  -g base-index 1         # start windows numbering at 1
set  -g renumber-windows on  # renumber windows when a window is closed
setw -g pane-base-index 1    # make pane numbering consistent with windows
setw -g automatic-rename on  # rename window to reflect current program
setw -g aggressive-resize on # aggressively resize the chosen window

# Others
#set  -g mouse on            # mouse mode
setw -g mode-keys vi         # start vi mode
set -g history-limit 65535   # num of history recoders
EOF
fi

if [ ! -f ~/.vimrc ]; then
cat <<-EOF >~/.vimrc
colorscheme desert

" vim color
if exists('$TMUX')
    set term=screen-256color
endif

" mouse type
if exists('$ITERM_PROFILE')
    if exists('$TMUX') 
        let &t_SI = "\<Esc>[3 q"
        let &t_EI = "\<Esc>[0 q"
    else
        let &t_SI = "\<Esc>]50;CursorShape=1\x7"
        let &t_EI = "\<Esc>]50;CursorShape=0\x7"
    endif
end

" for tmux to automatically set paste and nopaste mode at the time pasting (as happens in VIM UI)
function! WrapForTmux(s)
    if !exists('$TMUX')
        return a:s
    endif

    let tmux_start = "\<Esc>Ptmux;"
    let tmux_end = "\<Esc>\\"

    return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
endfunction

let &t_SI .= WrapForTmux("\<Esc>[?2004h")
let &t_EI .= WrapForTmux("\<Esc>[?2004l")

function! XTermPasteBegin()
    set pastetoggle=<Esc>[201~
    set paste
    return ""
endfunction

inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
EOF
fi
[ x"$1" == xconfig ] && exit 0

###
### Start Tmux ###
SESSION=leap                 # set session name

$CMD has -t $SESSION &>/dev/null
if [ $? != 0 ]; then
    $CMD new-session -s "$SESSION" -d -n "work1"
    $CMD split-window -v "top"

    $CMD new-window -t $SESSION:2 -n "work2"
    $CMD split-window -h

    $CMD new-window -t $SESSION:4 -n "work3"
    $CMD split-window -h

    $CMD new-window -t $SESSION:5 -n "work4"
    $CMD split-window -h

    $CMD select-window -t $SESSION:2
fi

$CMD -2 attach-session -t $SESSION

相关文章

  • 最简单最省事儿的方式上手用tmux

    tmux (https://github.com/tmux/tmux/wiki) 快捷方式 自动化脚本 安装完tm...

  • tmux使用介绍

    tmux简介 tmux,升级版本的screen,可以进行屏幕切割,操作更加简单便捷。 tmux模块 tmux使用C...

  • tmux安装与使用

    tmux 一、tmux是什么 tmux(terminal multiplexer)是Linux上的终端复用神器,可...

  • 公司网络不好试试Tmux

    同事分享的很棒的工具: Tmux 使用 1. Tmux是什么 1.1 Tmux的作用 命令行的典型使用方式是,打开...

  • 中山紫马岭公园的玫瑰花

    早上,送完孩子就到紫马岭公园走走。 走路是最简单的一种锻炼方式,也是最容易的,最省钱的一种。 对我来说,没有什么会...

  • Tmux使用心得

    tmux 环境的简单配置: https://github.com/gpakosz/.tmux 一些更改 开启滚轮 ...

  • 金钱并不是万能的

    对于一些简单问题,花钱来解决最容易也最省事儿,但是对于一些系统级的复杂问题,花钱就很难起到决定性作用了。 你为了练...

  • 【日更挑战赛】5/365 #方法#价值投资 #比定投更优的策略

    定投是世界上最安全、最简单、最省心的的投资策略呢?那有什么策略比定投更优呢? 【见】 首次看到这个策略的时候,是在...

  • 服务器上的编程之Tmux

    什么是 Tmux Tmux 官方 Wiki 简单来说,Tmux 是一个能够让你一个窗口当多个窗口使用的终端模拟器。...

  • CentOS 安装tmux

    centos 官网源中没有tmux,无法使用yum install tmux的方式安装。因此自己动手丰衣足食(编译...

网友评论

      本文标题:最简单最省事儿的方式上手用tmux

      本文链接:https://www.haomeiwen.com/subject/flgpfftx.html