exocron

This is my blog. There are many like it, but this one is mine.

Make Your Terminal More Awesome With Tmux

I was looking at my terminal this morning, and I was thinking, “Man, there has got to be something I can do to make this more awesome.” For some strange reason, I thought of making every terminal window I open start with tmux. This would give me a nice statusbar on each window with the date and time, and even allow me to split my terminal windows (usually I only want to split windows after I have started a long-running command, and I don’t already have tmux running).

Ooh...shiny green statusbar...

Anyways, after adding tmux to my bashrc, I came across some info (from the ArchWiki) on how you can share your tmux session across all of your open terminals. All I can say is, wow. I’ve adopted these scripts for my Xubuntu system, although it probably works without much modification for a host of distributions and terminal emulators.

Add this to the end of your .bashrc:

# If not running interactively, do not do anything
[[ $- != *i* ] ] && return
# If we're inside of tmux, do not do anything
[[ ! -z "$TMUX" ] ] && return

# Check if tmux session already exists
if tmux has-session -t "bashrc"
then
	# Attach new session to the existing session, and create a new window.
	# This has the effect of all bash windows being attached to the
	# same tmux session, even if they are viewing different windows
	# inside the session.
	CLIENTID=`date +%s`
	exec tmux new-session -d -t "bashrc" -s $CLIENTID \; set-option destroy-unattached \; new-window \; attach-session -t $CLIENTID
else
	# Create new tmux session and attach to it.
	exec tmux new-session -s "bashrc"
fi

After adding this to my .bashrc, subsequent terminal windows would be opened to a new window in tmux, but would also have access to all older windows. In addition, other terminal emulators that I’ve already opened have access to the new window. Windows also open in the correct directory if I right-click a thunar window and click “Open Terminal Here”.

Also, here’s a short video:

About

I'm a programmer. I also enjoy reverse-engineering and I'm focused on information security. Hobbies include but are not limited to video games, laser tag, hardware hacking, comics, and Futurama. I live in the internet.

Archives

Categories

RSS Feeds

Meta