Some iTerm2 hacking

The first thing I discovered is that when you go to install iTerm2’s shell integration it checks to see what shell you are using by reading the variable $SHELL, which is your accounts default shell, not necessarily the shell you are running.

Since my corporate Active Directory account sets my default shell to /bin/ksh (don’t ask, just don’t ask) this caused me a problem. In iTerm my default profile is set to run the command /bin/bash rather than my default shell. So to get shell integration installing properly I now set SHELL='/bin/bash' at the bottom of my bash profile.

My second piece of work was an improvement to imgls, this is a useful utility that displays a small thumbnail of any images in a directory listing. You can find the source in ~/.iterm2/imgls once you have installed shell integration.

I find that the thumbnails are sometimes a bit small. I usually use this utility to get a quick look at screen grabs when I’m writing doco so I need a bigger thumbnail. I added a -s parameter to specify the thumbnail size.

Change line 37 to

printf ";inline=1;height=$size;width=$size;preserveAspectRatio=true"

And then add this at line 68 (just after the check_dependency lines).

while [[ "$#" > 1 ]]; do case $1 in
    -s) size="$2";;
    *) break;;
  esac; shift; shift


If you want a larger default size change that size=${size=3} to a bigger number like 6.

It’s not terribly user friendly as I’ve written it since you need to specify -s <num> before any file parameter and forgetting to put the number in after -s can cause chaos but it works.

Given that I like the gnu ls I changed lines 58 and 60 to /usr/local/bin/gls -dhs "$fn". I also prefer to just see the file size for images, not the entire long ls line so the l became an s.

It was actually sloppy programming to have just ls there in the original. Always specify complete paths as it avoids problems with people that muck around with core utils like me. My ls is actually alias ls='gls $LS_OPTIONS -hF' and that caused problems to imgls. Since you’ve got the source open change it to /bin/ls if you use the Mac version of ls.

I may spend some time making the parameter order flexible and adding some error checking. Don’t hold your breath, though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s