tmux: The terminal multiplexer

tmux: The terminal multiplexer

tmux is a command-line tool that can create multiple virtual terminals in one terminal.

ref:
https://tmux.github.io/

Install

# on Ubuntu
$ sudo apt-get install tmux

 # on macOS
$ brew install tmux

$ tmux -V
tmux 2.6

Configurations

in ~/.tmux.conf

# prefix: Control + a
set -g prefix C-a

# kill-session: Control + a >> X
bind X confirm-before "kill-session -t ''"

# select-pane: Option + 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

# start numbering at 1
set -g base-index 1
set-window-option -g pane-base-index 1

# allow for faster key repetition
set -s escape-time 0

# rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
# CAUTION: not compatible with iTerm2
setw -g aggressive-resize off

set -g status-left-length 40

set -g mouse on

# list of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

After adding new plugins, you need to press Control + A >> I to fetch and install them.

ref:
https://github.com/tony/tmux-config/blob/master/.tmux.conf

Usage

$ tmux

$ tmux new -s your_project

$ tmux ls

$ tmux attach

$ tmux attach -t your_project

# list all windows with their layouts
$ tmux list-windows

$ tmux kill-session -t your_project

# kill all sessions
$ tmux kill-server

# reload settings
$ tmux source ~/.tmux.conf

Shortcut Keys

Control + a >> Shift + ?
list all shortcut keys

Control + a >> Shift + ""
split window horizontally

Control + a >> Shift + %
split window vertically

Control + a >> Arrow keys
Command + Option + Arrow keys
move the cursor between panels

Control + a >> d
dettach

Control + a >> c
create a new window

Control + a >> p
switch to the previous window

Control + a >> n
switch to the next window

Control + a >> w
Control + a >> 0-9
switch to window 0-9

Control + a >> [
enable copy mode, you can use Option + Up or Option + Down to scroll

Control + a >> Shift + &
kill the current window

Control + a >> X
kill the current session

ref:
http://manpages.ubuntu.com/manpages/zesty/en/man1/tmux.1.html

Tools

tmuxp

$ pip install tmuxp

An sample config:

in ~/.tmuxp/your_project.yaml

session_name: swag
windows:
- window_name: swag
  layout: main-horizontal
  focus: 'true'
  options:
    automatic-rename: 'off'
    main-pane-height: 35
  start_directory: ~/Projects/swag-server
  shell_command_before:
    - clear
  panes:
  - shell_command:
    - make up
  - shell_command:
    focus: 'true'
  - shell_command:
    - cd ../swag-bot
    - clear
$ tmuxp load swag

Layouts
https://tmuxp.git-pull.com/en/latest/examples.html

ref:
https://github.com/tony/tmuxp
https://github.com/tony/tmuxp-config

tmux-resurrect

Control + a >> Control + s
save tmux env

Control + a >> Control + r
restore tmux env

ref:
https://github.com/tmux-plugins/tmux-resurrect

Integration with iTerm2

You must create tmux session with -CC argument to integrate with iTerm2.

$ tmux ls && read session && tmux -CC attach -t ${session:-default} || tmux -CC new -s ${session:-default}

ref:
https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration

Computer Names for Sci-Fi Maniac Developers

Computer Names for Sci-Fi Maniac Developers

The list is collected from books I read, movies I watched, and video games I played.

  • ADA (from Zone of the Enders: The 2nd Runner)
  • Albedo (from Hyperion) --> used for one of my code projects
  • Asurada (from Future GPX Cyber Formula)
  • BrainPal (from Old Man's War)
  • ctOS (from Watch Dogs)
  • Deep Thought (from The Hitchhiker's Guide to the Galaxy)
  • Eddie (from The Hitchhiker's Guide to the Galaxy)
  • EDI (from Mass Effect) --> used for one of my code projects
  • EVA-00 (from Neon Genesis Evangelion)
  • EVA-01 (from Neon Genesis Evangelion)
  • EVA-02 (from Neon Genesis Evangelion)
  • Fine Till You Came Along (from Culture: Look to Windward)
  • GERTY 3000 (from Moon)
  • GLaDOS (from Portal)
  • HAL 9000 (from 2001: A Space Odyssey) --> used for one of my code projects
  • Jane (from Ender's Game: Speaker for the Dead) --> used for My AirPods
  • JARVIS (from Iron Man)
  • KOS-MOS (from Xenosaga)
  • Limiting Factor (from The Culture: The Player of Games)
  • MAGI (from Neon Genesis Evangelion) --> used for my iPad
  • Melchizedek (from Gunnm Last Order)
  • Mike (from The Moon Is a Harsh Mistress)
  • Of Course I Still Love You (from The Culture: The Player of Games)
  • Pip-Boy 3000 (from Fallout) --> used for my iPhone
  • Project 2501 (from Ghost in the Shell)
  • Samantha (from Her)
  • Skynet (from The Terminator)
  • SAL-9000 (2010: The Year We Make Contact)
  • Sol-9000 (from Xenogears)
  • Sophon (from The Three-Body Problem)
  • Tachikoma (from Ghost in the Shell)
  • TARS (from Interstellar)
  • TechnoCore (from Hyperion) --> used for my Macbook Pro
  • Ummon (from Hyperion) --> used for one of my code projects
  • VIKI (from I, Robot)
  • Wheatley (from Portal)

ref:
https://en.wikipedia.org/wiki/List_of_fictional_computers
https://en.wikipedia.org/wiki/Artificial_intelligence_in_fiction