Skip to content

Instantly share code, notes, and snippets.

@stevemadere
Forked from bigeasy/OSXScreen.md
Last active December 26, 2015 08:59
Show Gist options
  • Save stevemadere/7125852 to your computer and use it in GitHub Desktop.
Save stevemadere/7125852 to your computer and use it in GitHub Desktop.

Installing GNU Screen on OS X in Homebrew

I want to edit in one tab, run what I edit in the other. Typical multi-view stuff. I've used Terminal.app for the last few years. Lately, however, after not long enough, Terminal gets laggy when I switch between tabs.

The stutter between edit and run is annoying, an unnacceptable. One of the major reason I've chosen to work with character based UI is because it is snappy. There shouldn't be a lag while a screen of UTF-8 is rendered in a monospace font.

The lag gets progressively longer, chipping at my productivity with irritation. The only solution is to kill all my Terminals, which essentially kills my flow. Terminal.app won't remember where I was for me. I have to initialize ever tab.

GNU Screen

Back in the day I'd use GNU Screen. GNU Screen gives you different windows that you use keyboard commands to alternate between, but in a single terminal window.

I can't remember all that I did with it, but I developed a lot of muscle memory around it.

There was a lot more to learn about GNU Screen that I didn't learn. You can navigate your scrollback buffer from the keyboard, cutting and pasting. You can detach screen, close your terminal, then open a new terminal and reattach. Screen will be as you left it.

I'd much rather develop muscle memory that I can take with me to Linux. The only thing that Terminal.app gives me is tabs. Screen gives me tabs, keyboard scrollback, split windows, and saved detached sessions.

Collaboration!

The single most powerful feature of screen though is screen sharing. It provides the lowest-latency cross-platform remote collaboration environment possible (for users of terminal-based editors such as vim and emacs). When you are editing code, response time is critical and ssh with screen has the best by far.

To enable this amazing capability, simply create a ~/.screenrc file containing the following

multiuser on
acladd ANOTHER_LOGIN_ID

Then start a screen session with a name like this

screen -S $MY_SYMBOLIC_NAME

Then your collaborator whose login id is ANOTHER_LOGIN_ID can do this to share your screen

screen -x $MY_SYMBOLIC_NAME

When you get tired of sharing the screen, you can disconnect by typing <CTRL>-A d

256 Colors

Sadly, I found that the screen that comes with OS X does not support 256 colors.

Even more tragically, Apple also broke the shared screen functionality when they changed the permission model for calling kill(pid,0) in Snow Leopard. To get it working again, you need to make a tiny little patch to the source code which I've implemented here as an in-line perl script. This may create some security issues but hey, you are allowing this other guy to connect to your freaking screen. You should only be doing this on a well secured private host anyway.

Starting with this article GNU/Screen with 256 colours in Mac OS X, I built GNU Screen as follows.

git clone git clone git://git.savannah.gnu.org/screen.git
cd screen/src
# This is the code patch to fix multiuser mode:
perl -p -i -e  's/UserReturn\(kill\(pid, 0\)\)/return 0/' socket.c
mkdir -p /opt/etc
mv etc/etcscreenrc /opt/etc/screenrc
./autogen.sh
./configure --prefix=/opt/Cellar/screen/3.6.0  --enable-colors256 --with-sys-screenrc=/opt/etc/screenrc
make
make install
brew link screen
# This is also necessary to enable multiuser mode:
sudo chmod +s `which screen`

Now I can run screen and see that I have 265 colors and I can share my screen with collaborators.

@LeeXGreen
Copy link

This didn't work for me, until I changed all references to /opt/ to /usr/local/.

I think Homebrew changed their installation location at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment