You are here

How to use screen command with multiple windows

Do you love working on console without any graphical environment or any sort of GUI? If yes then read further. At sparxsys we work mostly on Linux based operating system like Fedora, Ubuntu and CentOS. No matter what the O.S. is we use Emacs a lot, we love it because this single editor can be used for various programming languages and also it is like a mini O.S. on its own. You can also manage your files using Emacs and it can be automated to load the modes based on the file extension. For instance if I open a PHP file emacs will automatically load the php-mode, for CSS or SCSS files the css-mode is loaded automatically.

This post is not really about emacs but rather another great command based utility called screen. I personally love working on terminal and I can do pretty much most of my content writing, coding stuff through terminal. I am really not very much comfortable in using heavy duty IDE like netbeans and eclipse. It is not only too heavy, consumes lot of memory but also it hassle to use.

Working on terminal is super efficient, you can do more work in less time without taking your hands off the keyboard. Using mouse for minimum cases like browsing sites. Most of the time we work directly on the servers where we don't have the access to GUI at all.

The main problem that I face when working on terminal is that there is just one window where you do your work. For instance let us say you are inside a particular directory and you quickly want to move out to another one to do something, then it is a pain, of course you can do "../../parent/directory" sort of a things, which work fine but usually I feel comfortable when I am inside a particular directory.

The good example is working with Omega 4 theme which is SASS based. Now if I am working directly on Vagrant, which is mostly the case with Drupal development for me. I would need to keep the "drush omega-guard" running to check any changes in the .scss files and also I need to update the code from emacs and may be need to move the files around. I can't do all that from single terminal session. One option is to have multiple ssh sessions running, which is fine but I would be dependent on Alt+tab key to switch among these multiple windows along with other windows on the desktop and another option is to use the screen command that lets you create multiple sessions within a single terminal window.

Not only that the screen utility can also be used to split into multiple windows. For installing screen on your linux distro use your standard package manager like apt-get or yum. In this post I just want to share some commands to get you started

Create a session

screen -S sessionname

Terminate Screen

screen -X -S SCREENID quit

All the shortcuts in screen is initiated with CTRL-a, but we use emacs for code editing hence we can't use CTRL-a shortcut. So we can change that for screen command.

Change CTRL-a to CTRL-l

Put this into ~/.screenrc

escape ^La

From now onwards we can use CTRL-l to initiate screen commands.

List screen and switch

CTRL-l "

Create new window

CTRL-l c

Switch between windows

CTRL-l n and CTRL-l p

Detach screen

CTRL-l d

Reattach screen

screen -r SCREENNAME

Split Horizontally

CTRL-l S

Resize vertical size

CTRL-l :resize 35

My terminal session looks like image attached with this blog. It is super productive to see lot of information in a single window and that too from a terminal session.