User Tools

Site Tools


linux:tmux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:tmux [2017/10/17 10:50]
admin created
linux:tmux [2017/10/17 11:19] (current)
admin
Line 11: Line 11:
 In all likelihood, you’ve probably already heard of tmux. However, you may not be using it everyday. If tmux is on your “Someday” list because you think it is too complicated (I mean, c’mon, the word “multiplexer” is just plain scary), then I am here to show you just how easy it is to put tmux into your workflow. In all likelihood, you’ve probably already heard of tmux. However, you may not be using it everyday. If tmux is on your “Someday” list because you think it is too complicated (I mean, c’mon, the word “multiplexer” is just plain scary), then I am here to show you just how easy it is to put tmux into your workflow.
  
-Simple Install+===== Simple Install ​===== 
 To start, you’ll need tmux (DERP). Depending on your platform, there are various (easy) ways to perform the install: To start, you’ll need tmux (DERP). Depending on your platform, there are various (easy) ways to perform the install:
  
-Mac OSX +==== Ubuntu/​Debian ====
-Use Homebrew. brew install tmux and you’re done.+
  
-Ubuntu/​Debian 
 There is a Ubuntu package so, sudo apt-get install tmux will work, but the installed package is 1.7 and we really want 1.8. To get 1.8, do the following (thanks to this article): There is a Ubuntu package so, sudo apt-get install tmux will work, but the installed package is 1.7 and we really want 1.8. To get 1.8, do the following (thanks to this article):
  
 +<code bash>
 $ sudo add-apt-repository ppa:​pi-rho/​dev $ sudo add-apt-repository ppa:​pi-rho/​dev
 $ sudo apt-get update $ sudo apt-get update
 $ sudo apt-get install tmux $ sudo apt-get install tmux
 +</​code>​
 It is not a huge deal if you cannot get 1.8 or don’t want to go through adding a PPA. You’ll just miss out on one of the cool features added in 1.8, which I will explain later. It is not a huge deal if you cannot get 1.8 or don’t want to go through adding a PPA. You’ll just miss out on one of the cool features added in 1.8, which I will explain later.
  
-Windows+==== Windows ​==== 
 No dice, unless you use Cygwin or install a VM with a *nix distrubution and then follow the instructions for Ubuntu. No dice, unless you use Cygwin or install a VM with a *nix distrubution and then follow the instructions for Ubuntu.
  
 Type the following to make sure all is well. Type the following to make sure all is well.
  
 +<code bash>
 $ tmux -V $ tmux -V
 tmux 1.8 tmux 1.8
 +</​code>​
 Hurray! tmux is installed! Hurray! tmux is installed!
  
-Simple Usage+===== Simple Usage ===== 
 Using tmux is as easy as typing tmux. When you do that, it just looks like your screen clears and you’re back at the same terminal prompt. A bit anti-climatic,​ maybe, but you’ve just stepped through the looking glass. Using tmux is as easy as typing tmux. When you do that, it just looks like your screen clears and you’re back at the same terminal prompt. A bit anti-climatic,​ maybe, but you’ve just stepped through the looking glass.
  
-tmux2+{{ :linux:tmux2-530x391.png |}}
  
 The more observant among you will notice that the terminal how has a green bar along the bottom. The more observant among you will notice that the terminal how has a green bar along the bottom.
  
-tmux2 2+{{ :linux:tmux2-2-530x37.png |}}
  
 If you are thinking that this is a status line for tmux, you’d be right. Right now, it tells me the date, time, the host, what “windows” are open (just 1 named “0:​bash”),​ and the name of the session (“0”). If you are thinking that this is a status line for tmux, you’d be right. Right now, it tells me the date, time, the host, what “windows” are open (just 1 named “0:​bash”),​ and the name of the session (“0”).
Line 49: Line 54:
 The status bar can also be configured to display more information,​ use different colors, and many (MANY) other things. In this article, however, we are only going to focus on windows and panes. The status bar can also be configured to display more information,​ use different colors, and many (MANY) other things. In this article, however, we are only going to focus on windows and panes.
  
-No Pane, No Gain+===== No Pane, No Gain ===== 
 I’ve already mentioned words like “session”,​ “window”,​ and “pane”. When you run tmux, it creates a new tmux session. A tmux session is, put simply, and container for windows and panes. A window contains one or more panes. I’ve already mentioned words like “session”,​ “window”,​ and “pane”. When you run tmux, it creates a new tmux session. A tmux session is, put simply, and container for windows and panes. A window contains one or more panes.
  
-tmux_digram+{{ :​linux:​tmux_digram2.png |}}
  
 Each pane and each window are a virtual terminal, it just happens to be that windows can contain panes. Panes and windows can swap places, as well, so a pane can be made a window and window can be made a pane. Each pane and each window are a virtual terminal, it just happens to be that windows can contain panes. Panes and windows can swap places, as well, so a pane can be made a window and window can be made a pane.
Line 58: Line 64:
 When starting life with tmux, I’d recommend you split your terminal into 1-3 panes for an “edit” window, and run other processes (like a rails console or tailing a log file) in their own windows. That is what we will walkthough today. When starting life with tmux, I’d recommend you split your terminal into 1-3 panes for an “edit” window, and run other processes (like a rails console or tailing a log file) in their own windows. That is what we will walkthough today.
  
-Windows into Your Application+===== Windows into Your Application ​===== 
 Let’s do this. Fire up a terminal and cd into the root of your application. I am using a Rails app here, but that is not important. Let’s do this. Fire up a terminal and cd into the root of your application. I am using a Rails app here, but that is not important.
  
Line 65: Line 72:
 This is the first window, which will be the “edit” window for our session. I want to see the editor, my tests, and what top(1) has to say about current affairs. Split the current window into two panes by typing: This is the first window, which will be the “edit” window for our session. I want to see the editor, my tests, and what top(1) has to say about current affairs. Split the current window into two panes by typing:
  
 +<code bash>
 CTRL+B % CTRL+B %
 +</​code>​
 +
 Whoa! That key-combination is a bit cryptic, no? It is, but that’s OK. Learning the tmux commands is no different than learning anything else, and they can be easily changed. Whoa! That key-combination is a bit cryptic, no? It is, but that’s OK. Learning the tmux commands is no different than learning anything else, and they can be easily changed.
  
Line 72: Line 82:
 Your terminal should now look like: Your terminal should now look like:
  
-tmux_split1+{{ :linux:tmux_split1-530x386.png |}}
  
 Now, we want to split the right-hand pane into 2 panes that are stacked vertically. Your cursor should be in the right-side pane. Type: Now, we want to split the right-hand pane into 2 panes that are stacked vertically. Your cursor should be in the right-side pane. Type:
  
 +<code bash>
 CTRL+B " CTRL+B "
 +</​code>​
 +
 and your terminal should look like: and your terminal should look like:
  
-tmux_split2+{{ :linux:tmux_split2-530x389.png |}}
  
 With the panes setup, the commands for each pane need to be launched. Since your cursor is now in the bottom, right-side pane, type top and watch top fire up. OK, switch to the top, right-side pane and type a command. For me, I’ll use rake test, but I would generally make this pane run the automated tests using guard or something similar. With the panes setup, the commands for each pane need to be launched. Since your cursor is now in the bottom, right-side pane, type top and watch top fire up. OK, switch to the top, right-side pane and type a command. For me, I’ll use rake test, but I would generally make this pane run the automated tests using guard or something similar.
Line 85: Line 98:
 Before you can do that, though, you need to know how to switch panes, don’t you? To move from the bottom, right-side pane to the top, right-side pane: Before you can do that, though, you need to know how to switch panes, don’t you? To move from the bottom, right-side pane to the top, right-side pane:
  
 +<code bash>
 CTRL+B <UP ARROW> CTRL+B <UP ARROW>
 +</​code>​
 +
 Same prefix, new suffix to the command. This one makes a bit more sense; to move up, use the up-arrow. Now type the command to fire up your tests. Same prefix, new suffix to the command. This one makes a bit more sense; to move up, use the up-arrow. Now type the command to fire up your tests.
  
Line 92: Line 108:
 Here is my edit pane: Here is my edit pane:
  
-tmux_edit_pane+{{ :linux:tmux_edit_pane-530x390.png |}}
  
 OK, the edit pane is done. Pro tip: If you are using tmux 1.8, you can toggle the curent pane into full-screen by typing: OK, the edit pane is done. Pro tip: If you are using tmux 1.8, you can toggle the curent pane into full-screen by typing:
  
 +<code bash>
 CTRL+B ​ z CTRL+B ​ z
 +</​code>​
 +
 I LUUUUUV this feature, because it means I can full-screen my tests when they are failing and navigate around that pane more easily, then return it to its original size when done. I LUUUUUV this feature, because it means I can full-screen my tests when they are failing and navigate around that pane more easily, then return it to its original size when done.
  
 Quickly now, I’ll show you how to add a window so you can fire up other services related to your app in the tmux session. To add a new window: Quickly now, I’ll show you how to add a window so you can fire up other services related to your app in the tmux session. To add a new window:
  
 +<code bash>
 CTRL+B c CTRL+B c
 +</​code>​
 +
 You are now in a pane-free (HA!) terminal and the status bar shows two windows (0 and 1). Fire up the rails console or whatever you like here. You are now in a pane-free (HA!) terminal and the status bar shows two windows (0 and 1). Fire up the rails console or whatever you like here.
  
-tmux_new_window+{{ :linux:tmux_new_window-530x389.png |}}
  
 Add as many windows as you like using that same key combination. When you want to switch between windows 0 and 1, type: Add as many windows as you like using that same key combination. When you want to switch between windows 0 and 1, type:
  
 +<code bash>
 CTRL+B <window number> CTRL+B <window number>
 +</​code>​
 +
 where is 0 or 1. where is 0 or 1.
  
 Now you can jump back and forth at your heart’s consent. Now you can jump back and forth at your heart’s consent.
  
-The End is Near+===== The End is Near ===== 
 The last thing I’ll mention is how you detach from and end a session. When you are in a session, you are “attached” to it. The tmux command creates a new session and attaches the current terminal. To detach, type: The last thing I’ll mention is how you detach from and end a session. When you are in a session, you are “attached” to it. The tmux command creates a new session and attaches the current terminal. To detach, type:
  
 +<code bash>
 CTRL+B d CTRL+B d
 +</​code>​
 +
 You’ll see something like [detached] and you’ll be back at your no-status-bar,​ regular, old terminal. If you type tmux ls, you will see a list of sessions: You’ll see something like [detached] and you’ll be back at your no-status-bar,​ regular, old terminal. If you type tmux ls, you will see a list of sessions:
  
-tmux_ls+{{ :linux:tmux_ls.png |}}
  
 All the stuff you had running in that session is still cruising right along. You can reattach to it by typing: All the stuff you had running in that session is still cruising right along. You can reattach to it by typing:
  
 +<code bash>
 tmux attach -t 0 tmux attach -t 0
 +</​code>​
 +
 where -t stands for “target” and 0 is the session name. Now, go ahead and detach again. where -t stands for “target” and 0 is the session name. Now, go ahead and detach again.
  
 To end/kill the session, type To end/kill the session, type
  
 +<code bash>
 tmux kill-session -t 0 tmux kill-session -t 0
 +</​code>​
 +
 This will end the session, so if you do another tmux ls, you will see zero sessions running. By the way, if you exit out of all the windows in a session, the session will exit as well. This will end the session, so if you do another tmux ls, you will see zero sessions running. By the way, if you exit out of all the windows in a session, the session will exit as well.
  
-Next Steps+===== Next Steps ===== 
 This article just skims the surface of what tmux can do for you. However, you can apply what you learned today and be more productive in your development environment without investing another second of time learning about tmux. This article just skims the surface of what tmux can do for you. However, you can apply what you learned today and be more productive in your development environment without investing another second of time learning about tmux.
  
linux/tmux.1508230201.txt.gz · Last modified: 2017/10/17 10:50 by admin