Archive for the 'Uncategorized' Category

How to switch gnu screen windows in iTerm2 via keyboard shortcuts

I’m obsessed with having optimal keyboard shortcuts with whatever program. I recently switched from using client-side textmate to server-side vim as I want to move as much as possible to the cloud.

I have looked for a good way to switch windows in gnu screen for a long time without having to use ctrl-a 1. That’s what I came up with:

(more…)

Python: display refreshing status (like top)

In scripts I often want to display some status information (e.g. progress), this can be achieved with e.g.:

PYTHON:
  1. print "progress: %i %%\r" % i,
  2. sys.stdout.flush()

but this just works for one-liners. I wanted to have what top or less do: open a new "window" and being able to write everywhere in the window, not just on the last line.

Found out that curses does exactly that - but I didn't find a stripped-to-the-bare-necessities-example, so here you are:

PYTHON:
  1. import curses, time
  2. from datetime import datetime
  3. w = curses.initscr()
  4. try:
  5.   while True:
  6.     w.erase()
  7.     w.addstr("some status..\ncurrent time\n%s" % datetime.now())
  8.     w.refresh()
  9.     time.sleep(1)
  10. finally:
  11.   curses.endwin()