Archive for January, 2011

A better git log and the wonders of git tig

Posted on January 16th, 2011 in git | No Comments »

I was looking for a remote terminal-friendly version of gitk for visualizing branch and merges and as of yet the closest I’ve gotten is this awesome log command (compliments of this well-done git tutorial):

git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short

It wasn’t as full featured as I liked but did the job and doesn’t require installing an extra package. Recently though, I stumbled on a colorful text-based git frontend call tig which is quite handy. Check out the screenshots here. It’s fast and effortless to dig around your repository, drill down wherever you need, and you can even pipe regular git commands to it to see them in interactive full color. Installing it is a breeze with (yum install tig or apt-get install tig) or you can install from source. From here, type tig in your working directory and follow these commands. Checkout tig blame too!

I’d give a longer review on it with screenshots but someone already has here.

I default tig to show the rev-graph (shown here) and use relative dates by adding the following to my global git config in ~/.gitconfig:

   show-date = relative
   author-width = 8
   show-rev-graph = yes

You can really modify the short cut commands and colors to your liking using the man file.

Sharing one .emacs file for both Carbon or Aquamacs and shell emacs without throwing errors

Posted on January 6th, 2011 in emacs | 2 Comments »

I love running Carbon Emacs locally as it gives me the ability to keep everything in one place. Thanks to gleaning much of my friend Pavel’s emacs settings, my emacs fullscreens (white on black) when loaded and gives me such things as the date, time, and battery life at the bottom. I have more colors than shell emacs, can open remote files using tramp, and most importantly can use my command key as meta. Life is good.

Sometimes though, its faster to just SSH right into a remote machine and work from there if I know I’ll be doing a lot of random file accessing / manipulating. The problem is: I’d love to keep all my .emacs preferences (colors, shortcuts, etc) wherever I go without having to maintain two versions.

Syncing is not really the issue here: rsync or dropbox will do the job, but some of my Carbon Emacs settings will throw errors when loading from shell emacs. I talked to the guys in #emacs on freenode on how to specify a different .emacs file for different version of emacs and it looks like you can’t really change where it gets loaded from. Ultimately, the best answer is to just use a when statement right in your preferences file. display-graphic-p is the key here for detecting a window-system-based emacs:

;; load these only if using window-system emacs
(when (display-graphic-p)
  ;; disables scrollbar
  (scroll-bar-mode -1)
  (menu-bar-mode -1)
  ;; disable the top toolbar
  (tool-bar-mode -1)
  (display-battery-mode 1))

Sharing remote terminal session between two users with Tmux

Posted on January 2nd, 2011 in tmux, unix | 6 Comments »

I’ve yet to write my “Wonders of Tmux” entry but always have small tidbits to give in the meantime.

Sometimes sharing your whole desktop via Skype, Teamviewer, or some other screen-sharing system is overkill, at the very least harder to read and control remotely. Sharing a terminal session between two (or more) users is great for pair programming (especially if both users are vi or emacs users) or for one user to educate, walk-through, or troubleshoot something with another remote user – also great for showing how Tmux works! One can even split the screen in half and be SSH’d into multiple machines together!

There’s three ways that users can share a terminal session together. The first way requires a little more work from the person sharing their tmux session, the second and third require either sudo rights or being able to su to the other user’s account.

Similar to SSH, when you create a tmux session, it creates a temporary socket in the /tmp directory with the tmux user owning the file. This makes it unaccessible by other users.

Allow another user access to your tmux session:

# specify the name of your tmux socket with -S when creating it
tmux -S /tmp/pair
# chmod to allow other users to access it
chmod 777 /tmp/pair
# now the other user can connect with
tmux -S /tmp/pair attach

Sudo your way into another users tmux session

# Have the user create a tmux session
# ls -al /tmp to see which tmux session is owned by the user you want to share sessions with then
# in the following example tmux-502 is the tmux socket folder of the example user 
sudo tmux -S tmux-502/delfault attach

su your way into the session

su username # need user's password or sudo
tmux attach

Installing Tmux 1.4 from source for Centos

Posted on January 2nd, 2011 in tmux, unix | 2 Comments »

The newest version of Tmux (1.4, released Dec 2010) has a bunch of fixes and subtle workflow enhancements. Unfortunately Yum still only has 1.3.

You can compile it from source here. I did and got the following errors:

# ./configure
Configured for Linux
# make
cc -DBUILD="\"1.4\"" -std=c99 -D_GNU_SOURCE -D_POSIX_SOURCE -iquote.   -c -o attributes.o attributes.c
In file included from attributes.c:23:
tmux.h:30:19: error: event.h: No such file or directory
In file included from attributes.c:23:
tmux.h:830: error: field 'name_timer' has incomplete type
tmux.h:1032: error: field 'key_timer' has incomplete type
tmux.h:1093: error: field 'event' has incomplete type
tmux.h:1117: error: field 'repeat_timer' has incomplete type
tmux.h:1139: error: field 'identify_timer' has incomplete type
tmux.h:1142: error: field 'message_timer' has incomplete type
make: *** [attributes.o] Error 1

After checking around, I discovered I was missing these two packages:

yum install libevent-devel
yum install ncurses-devel ncurses

Recompile and you should be golden.

Addendum: on a fresh Ubuntu install it’s:

apt-get install libevent-dev
apt-get install libncurses5-dev libncursesw5-dev

Fixing Tmux create session failed: : Exec format error

Posted on January 2nd, 2011 in tmux, unix | 2 Comments »

This error happened to me whenever I tried to run Tmux as a non-root user. Most likely if this is happening to you, you’re using Linode VPS like I am or have a similar setup.

The answer is that devpts is missing. Trying running the following as a non-root user, and Tmux should work:

sudo mount devpts /dev/pts -t devpts

What is devpts?

You probably don’t want to run this command every time (or give your users access to sudo.)
Add this to your /etc/fstab and you can continue with your tmux screen splitting.

tmpfs /dev/shm tmpfs defaults 0 0 
devpts /dev/pts devpts gid=5,mode=620 0 0 
sysfs /sys sysfs defaults 0 0