Posts Tagged ‘ desktop

Automatically start tmux

This guide describes how to setup tmux to automatically launch as part of a user’s shell environment. If you don’t have tmux installed, you can use a package manager or follow my guide to compiling tmux. In order to launch tmux with the user’s shell session, we need to add a line to that user’s .bashrc file.

This command will open the .bashrc script for the current user in vim for editing.

vim ~/.bashrc

Now add the follow lines to the user’s .bashrc.

if [ `which tmux 2> /dev/null` -a -z "$TMUX" ]; then
    tmux -2 attach || tmux -2 new; exit
fi

Now to break down what the above lines of code do:

if [ $TERM != "screen-256color" ] && [ $TERM != "screen" ];“, checks the $TERM environment variable to see if tmux is already running; in order to avoid an infinite loop of launching tmux.

tmux attach || tmux new; exit“, this launches tmux, launches tmux and attaches to any running session; if there are no sessions of tmux running then it creates a new one. exit, this closes the shell session running tmux when the last tmux window is closed.

Revisions

  • 2012-12-11: Rewritten for clarity.

tmux empty window name

After compiling the newest version of tmux 1.5, I started tmux only to discover that the window name was missing from all of the windows. So all of the windows looked like

0:* 1:-

They should look like

0:bash* 1:vim-

See how the name of the running command is missing in the first example.

After several hours of troubleshooting, I finally figured out the problem was with my user’s prompt string. There was an extra line being added to the front of the prompt string that was causing the problem. I figured this out by temporally creating a new user, so that I could test tmux with a clean user environment and then slowly moving files (e.g. .bashrc, etc…) from my environment to the test environment. I opened tmux after I moved each file until it broke. I then commented all of the lines in the problem file, commenting a line or function at a time until I found the problem line.

How to compiling tmux 1.5 for Ubuntu 10.04

Introduction

I’ve decide to tmux a serious try on my Ubuntu 10.04 server.

Dependencies

The first step is to install the dependencies, which are all conveniently available from the Ubuntu repositories.

This command will install the dependencies required to compile tmux from source code.

sudo apt-get install build-essential debhelper diffstat dpkg-dev fakeroot g++ g++-4.4 html2text intltool-debian libmail-sendmail-perl libncurses5-dev libstdc++6-4.4-dev libsys-hostname-long-perl po-debconf quilt xz-utils libevent-1.4-2 libevent-core-1.4-2 libevent-extra-1.4-2 libevent-dev

You may already have some of these dependencies installed, depending on if you have compiled applications from source code before.

Download

The next step is to download the source code for tmux. It can be found on SourceForge at

Extract

Now its time to extract the source code you just downloaded.

tar xvvf tmux-1.5.tar.gz

Compile

The next step is to configure and compile tmux.

This command will move into the new directory with the source code.

cd tmux/

This command will check for dependencies and configure the install. Setting --prefix will install tmux to /usr/bin, which is the same directory the package manager version of tmux installs too.

./configure --prefix=/usr

This command will make the tmux.

make

This command will install tmux to /usr/bin/tmux.

sudo make install

Conclusion Thats it, the last thing to do is start tmux.

This command will start tmux.

tmux

Automatically start screen

This guide describes how to setup screen to automatically launch as part of a user’s shell environment. If you don’t have tmux installed, you can use a package manager. In order to launch screen with the user’s shell session we need to add a few lines of code to that user’s .bashrc file.

This command will open the .bashrc script for the current user in vim for editing.

vim ~/.bashrc

Now add the follow lines to the user’s .bashrc.

if [ $TERM != "screen" ]; then
    screen -dR; exit
fi

Now to break down what the above lines of code do:

if [ $TERM != "screen" ];“, checks the $TERM environment variable to see if screen is already running; to avoid an infinite loop of launching screen.

screen -dR; exit“, launches screen attaching to any running screen sessions; if there are no sessions of screen running then it creates a new one. exit, this closes the shell running underneath screen when the last screen session is closed.

Revisions

  • 2011-05-23: Rewritten for clarity.
  • 2012-12-11: Rewritten for clarity.