Boost your CLI environment – part 3

In the part 2 we have described the powerfulness of terminal multiplexers and reviewed one of the most popular terminal utilities – Tmux. Such kind of multiplexers might greatly boost your performance in handling different CLI operations. Let’s go forward and imagine the trivial situation, when you have created your own handy CLI environment with many terminal windows in one tab or so. You have everything under your hand but sooner or later you have to reboot your computer because of a new system update or installing some applications that require the system restart. In this case, your terminal multiplexer process will be shut down and you will lose all your settings. Fortunately, there are few lovely utilities that help save all your windows/tabs configurations and allow to recreate the entire tabs with windows.

One of our favorite utility for creating predefined Tmux tabs configurations – Teamocil

To install the utility you need to have a Ruby gems manager installed on your system. The good news are that it’s installed out of the box in OSX 10.6+. If you are lucky OSX user, run the following command to install Teamocill:

gem install teamocil

Then, we need to create a directory where all custom preconfigured tabs will be stored:

mkdir ~/.teamocil

As you remember, in the very first article about CLI improving we have described a great shell – ZSH. If you use this shell, add the following line:

compctl -g '~/.teamocil/*(:t:r)' teamocil

to your ~/.zshrc file. We will explain this step later in this article.
Now we will create our first windows configuration. It’s quite easy, we need a new YML file inside of the directory created on the previous step. The name of the file can be custom, however, we recommend to use short and constructive names without white spaces. This approach will save your time upon accessing the necessary configuration name. Let’s create the new file ~/.teamocil/dev_atwix.yml with the following content:

windows:
  - name: Test
    root: ~/
    layout: even-vertical
    panes:
        - commands:
            - top
        - commands:
            - vim
          focus: true

The name parameter is used as a Tmux tab name and that’s really handy. The root parameter is a path where all windows in the tab will be started. In the layout parameter you can specify how exactly windows will be arranged inside of the tab. Here are the few examples of the layout’s values:

even-vertical

.-------------------------------------.
| (0)                                 |
|                                     |
|                                     |
|                                     |
|-------------------------------------|
| (1)                                 |
|                                     |
|                                     |
|                                     |
'-------------------------------------'

even-horizontal

.------------------.------------------.
| (0)              | (1)              |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |                  |
'------------------'------------------'

main-vertical

.------------------.------------------.
| (0)              | (1)              |
|                  |                  |
|                  |                  |
|                  |                  |
|                  |------------------|
|                  | (2)              |
|                  |                  |
|                  |                  |
|                  |                  |
'------------------'------------------'

tiled

.------------------.------------------.
| (0)              | (1)              |
|                  |                  |
|                  |                  |
|                  |                  |
|------------------|------------------|
| (2)              | (3)              |
|                  |                  |
|                  |                  |
|                  |                  |
'------------------'------------------'

The panes section contains all windows and commands for these windows. In our case, we have two windows (one command corresponds to one window in our example) with a single command in each window. By setting the focus parameter you can make a specified window active upon the tab creation.
Now, type in your terminal: “teamocil dev” and press the TAB key. That’s where the magic happens: the name of your preconfigured window should be suggested automatically. It’s the purpose of the ZSH configuration we have added before to the configuration file (please note, you might need to start a new ZSH session to make the autocomplete work). Now press Enter and you should see the newly created tab with two windows. In the first window you see the output of Top utility execution and in the second one you have Vim editor opened. It’s really cool, isn’t it? Now you can create your own configurations. Remember that for each new configuration you should create a new file in the ~/.teamocil/ directory.

It’s always pleasure to see your opinions and questions, so feel free to leave your thoughts in the comments. Good luck with your experiments.