Category Archives: Linux

A little development environment in vim and tmux

I’ve been doing a little project and took a moment to get a bit better at using tmux.

Every time I go into this project I set up some splits. A main window where I’ll edit files using vim, then I split a pane off to run the code or test suite on every save. Another split where I pip install after any changes to my requirements.txt file.

Since I do the same thing repeatedly I was pretty sure tmux has a way to set this up so I don’t need to do it by hand. I tried using tmux session saving plugins, but they are too much for what I need right now.

Turns out tmux is incredibly easy to script. This gist is very long and very informative on how to split windows in tmux and covered everything I needed.

#! /bin/sh

# split -h horizontally to take up 30% of the width to run my __main__.py file on every save of a python file
# this is -d detached so that focus remains on the main window
tmux splitw -d -h -p 30 'ls *.py | entr -c env/bin/python . ./goodreads_library_export.csv data.csv ~/books'
# split my second pane vertically with 20% for rerunning pip installs on save of requirements.txt
tmux splitw -d -t 2 -p 20 'ls requirements.txt | entr -c env/bin/pip install -r requirements.txt'
# create a little detached shell just in case I need to try something
tmux splitw -d -t 3
# open up the python files in tabs in my main pane
vim -p *.py 

entr is a great little tool I like for monitoring for file changes and running a command in response.

a quick development environment for a project

Grepping a process output

I’m just noting this down because I had to do a lot of reading to get this right. Now that I’m actually using log libraries in a good way for my scripts, I want to dial up and down the log level easily – but setting the loglevel on my overall script to debug makes EVERYTHING output, and I don’t really need every library’s output. I’m sure there’s a better way to control the log level of a specific logger for my script from the command line, but this works for me in a quick and dirty way.

env LOGLEVEL=DEBUG ./myscript.py |& grep my_logger_name

I set the log level for just this run, then use the |& to capture both stdout and stderr, then pass that to grep.

Making the switch to Ubuntu

Yesterday morning, the 7.10 version of Ubuntu was released. It’s supposed to be chock full of goodness, so my neighbor Lawyer Matt and I had an install party with Aaron and Ian.

I dug out an old IBM Thinkpad T20 laptop that had been lying around and we got to it. I’d tried various Linux installs before, including Ubuntu. It always got down to having to know far to much about the internals than I wanted to.

This was a huge difference. The basic install went very smooth. I hit one snag. This old laptop had a PCMCIA wifi card that wasn’t recognized. Aaron found the solution for my Linksys WPC54G on the Ubuntu forums. With that out of the way, it is working. I’m impressed by how simple and smooth the experience is so far. Of course, the experience so far is mainly checking gmail, playing a movie, and writing this post.