A week or so ago a colleague turned me on to oh-my-zsh and I just went down the rabbit hole. I have always found the built-in Terminal in macOS (formerly OS X) to be bland and boring, but never really sat down to try to change it. I started using iTerm2 awhile ago, but again, never tried to 'spice it up' so to speak. Now I did and I came up with this:
What is iTerm2? ITerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.12 or newer. ITerm2 brings the terminal into the. Jan 05, 2016 tmux (short for Terminal MUltipleXer), a simple and modern alternative to the well-known GNU screen, and will enable you to access and control a.
First off, make sure you're using iTerm2, if you're not already.
Next, we will have to install oh-my-zsh and tmux before setting up Powerlevel9k and your vim settings. There are a few caveats to getting everything setup neatly on Mac, so this post will go over that.
I used Homebrew to install tmux by simply typing the following:
If you don't have brew installed, you can do so by typing:
You can follow the documentation on GitHub, or simply use the following command:
After the install completes, you will want to enable some plugins and set a theme in your .zshrc file.
The plugins I have enabled are as follows:
Note: I had to manually install the following:
- zsh-completions
- zsh-autosuggestions
- zsh-syntax-highlighting
- zsh-autosuggestions
- zsh-syntax-highlighting
Next, the theme I used is Powerlevel9k, which I will get to next. To set it in my .zshrc file I used:
Remote Desktop capabilities refers to the ability to run and operate the desktop and operating system of a computer that is not your workstation. Remote desktop connection for mac. Using a remote desktop session provides the ability to control the “remote” workstation and use the files and software that are saved or installed onto that workstation.
The elbow macaroni in this mac and cheese recipe cooks per the package instructions, and while you wait for it to cook, you can whip up the irresistible cheese sauce with ingredients you probably already have on hand. Recipe for mac and cheese casserole.
Luckily, the install for Powerlevel9k is super simple for oh-my-zsh. Simply run the following command:
![Tmux for macbook pro Tmux for macbook pro](/uploads/1/3/4/1/134109590/346868322.png)
In most cases, you will need a powerline font. Powerline was a bitch to try to install on macOS with the new python packages, so I used tools that were inspired by it. The font I used is here; alternatively, you can install all powerline fonts by running:
You will need to set whichever font you want in your iTerm2 preferences. Note the font selected in my preferences:
Now that you have oh-my-zsh, tmux, and powerlevel9k installed, let's get to configuring everything.
Configuration
First, I selected the 'Darkside' color preset for iTerm2 because it reminded me of Star Wars. You can get a bunch of presets for iTerm2 here.
My terminal was inspired by a bunch of different user's screenshots, but two that stand out are Semartin's and Sevenfoxes', specifically because of the Spotify, wifi, and battery info. Rather than having the info show in my terminal, I opted to include it as part of my tmux configuration. In order to have tmux launch every time I opened iTerm2 (and thus, zsh), I needed to add the following to my .zshrc file:
My full zshrc file can be found here.
I ultimately took what I needed from their .tmux.conf configs and threw them into .sh scripts, which can be accessed here. My status line config for my .tmux.conf is as follows:
My full tmux.conf can be found here. Note: To get the now_playing.sh with Spotify to work, you will have to install shpotify:
I also installed the tmux-current-pane-hostname plugin (bottom right corner) so it will auto populate with the hostname when I am connected to an ssh session, or disply my hostname when disconnected.
Vim
Last, but not least, Vim! I had a hell of a time configuring Vim at first because I was trying to set it up using Powerline. I used this post as a guide, but was unable to configure things the way I wanted. Regardless, I am including the link in case it's helpful to you. I ended up choosing vim-airline because it's lightweight and simple.
To start, I configured my .vimrc file to use Vundle.
Then, put this at the top of your .vimrc file:
Next, to install plugins type 'vim +PluginInstall +qall' from command line or launch vim and run ':PluginInstall'
After you have Vundle setup, you can add these two plugins to your .vimrc and run your preferred command to install the plugins again:
This will install vim-airline and vim-airline-themes.
Now, to always show the statusline in Vim, you have to add:
I went with the wombat colorscheme for now. Also, I found a bunch of vimthemes here. For my vim-airline plugin, I went with the bubblegum theme.
Tmux Mac Scroll Up
Next, I wanted to install Nerdtree, but first I decided to install Pathogen to keep present and future installs simple:
I added the following to my .vimrc to enable pathogen:
Now I could install Nerdtree:
I added the following minor customizations, again, to my .vimrc to tell Nerdtree to startup with Vim every time, map the NerdTreeToggle to 'Ctrl+n', and have the cursor stay in the edit area by default on launch.
My complete .vimrc file can be accessed here.
Finally, my iTerm2 configuration, as well as every dotfile and .sh mentioned here, can be downloaded here.
Learn more on ruby with our tutorial Setting Up Automated Testing with RSpec on SitePoint.
A few times a year, I find something that transforms or enhances my development environment. Examples in the past few years are: Github , vim, and zsh (more specifically, on-my-zsh .)
Sometime in the last year or so, I started using another development transformer: Tmux . What is tmux? According to its site:
tmux is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.
I first learned about tmux from Evan Light (@elight) when I engaged him topair program with me eons ago. I was stunned at how easy tmux made it for Evan and I to collaborate in real-time. My reaction was a bit like an unfrozen caveman. I marvelled at the technology, presuming only advanced beings, like Evan, could wield such power. I put it on my “Someday” list and went back to my stone tablets.
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
To start, you’ll need tmux (DERP). Depending on your platform, there are various (easy) ways to perform the install:
Mac OSX
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):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
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.
Hurray! tmux is installed!
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.The more observant among you will notice that the terminal how has a green bar along the bottom.
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”).
When you start tmux with no arguments, it names the session using a zero-based list that increments by one for every current tmux session. As you might have guessed, you can name your sessions whatever you like, but we won’t get into that today.
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
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.
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.
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
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.Now, type
tmux
.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: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.
It is worth noting,however, that the
CTRL+B
portion of that macro is called “the prefix”. CTRL+B
is the default prefix for tmux, but you won’t be surprised to know that most people change it.Your terminal should now look like:
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:
and your terminal should look like:
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.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:
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.
Can you figure out how to move to the left-side pane? Once you do, launch your editor. I use VIM, so I type
vim
.Here is my edit pane:
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:
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:
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.
Add as many windows as you like using that same key combination. When you want to switch between windows 0 and 1, type:
where is 0 or 1.
Now you can jump back and forth at your heart’s consent.
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: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:All the stuff you had running in that session is still cruising right along. You can reattach to it by typing:
where
-t
stands for “target” and 0
is the session name. Now, go ahead and detach again.Tmux Macro
To end/kill the session, type
Install Tmux For Mac
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
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.
Tmux-cssh For Mac
But, you aren’t that kind of person, are you? Once you get comfy with what you’ve learned here, this is what I recommend you do next:
- Buy the Tmux Book and read it. It’s great.
- Create your .tmux.conf file and start changing tmux to suit your needs. There are LOADS of examples and it makes tmux even better.
- Check out tmuxinator for setting up named tmux environments that fire up a bunch of panes and windows in a new session with a simple command.
- Pair program with someone using tmux as the way to collaborate in real-time. It’s mind-blowing.
Wrap Up
The goal of this article was to get you going with tmux in as simple a way as possible. I am now at the point where I start tmux up to do just about everything. I love convenience of splitting a window into panes and running a quick command without leaving my current window. I think you’ll find it just as useful.
Tmux Mac Copy To Clipboard
Learn more on ruby with our tutorial Setting Up Automated Testing with RSpec on SitePoint.