Dealing with oh-so-many terminal windows

I have a problem. I have too many terminals and they tend to get lost. Emacs and vim and probably other editors are good at dealing with the problem of too many files, you just give every file a name, and then give people an easy way of finding open files by name.

I want to be able to do this with terminals.


Using screen

Screen works quite well for this: it allows you to name open terminals and then re-open these terminals by name. I’ve made this work by having an X terminal that connects to an existing instance of screen, this allows me to have a half-dozen interfaces to the same instance of screen at the same time.

However this approach has a couple of problems.

  • No completion of terminal names (it does, however, allow you to just write buffer name prefixes)
  • The default maximum number of windows isn’t high enough (the maximum of 40).
  • You end up pressing F quite, as terminals seem to get temporarily broken every time you resize.
  • Having a screen window open in two x terminals of different sizes confuses clients.

Trying to do this same in emacs

This would be a slightly nicer approach since emacs is awesome – and ido mode’s buffername completion is great.

However, some niggles in emacs have stopped me from doing this.

No curses in eshell

Emacs provides a light-weight shell (eshell). This allows you to interact will using your shell (copy and paste searching backwards etc). However it breaks curses, so no less, no mutt, no vim. This counts as unusable to me, as I tend to do things like open less on several hundred megabyte files on a remote machine.

ansi-shell to the rescue

Ansi-shell however does support curses, and vim and mutt, and beautiful colours. So this looked hopeful.

But not quite…

However, ansi-term just doesn’t quite work for the following reason:

  • mutt doesn’t work. If you resize a window while using mutt, mutt breaks and draws things in random places
  • Not fast enough! I like streaming large files with the F command in less, this can bring my terminal grounding to a halt

So yes, I’m settling with hacked version of screen for the moment.

Increasing the maximum number of screen windows

I’m not quite sure why I need more than 40 terminals but it appears that I do. I like to have a terminal for each different class of thing I’m doing (like reading though code, fixing bugs on by machine, doing things in a source tree, running tests, doing some recording to debug these tests, deploying, playing in a python shell, doing some stats in R) and then terminals logged into half a dozen machines, as well as poised to look at logs on these machine. The limit of 40 terminals poses a problem here, this is made worse by the fact that when the world catches file you often want to open a lot of new terminals – hitting up against limits exactly when you want to do things is not fun.

We can however increase screen’s window limit by rebuilding. On ubuntu we can do the following

apt-get source screen
cd screen-blah-blah
vim config.in
# Set default MAXWIN to something sane like 500
dpkg-buildpackage
cd ..
dpkg -i <deb file that dpkg-buildpackage dumped in your parent directory>
</pre>

This will work equally well for other debian-based builds (one presumes).

November 25, 2012 at 9:24 pm Leave a comment

Power of Habit Summary

The Power of Habit by Charles Duhigg


What is it?

Journalistic pop-science. An eclectic collection of interesting and useful facts with a loose over-riding theme. Very exciting if you don’t know most of these facts, slightly annoying if you do. Has references to relevant material.


Thesis in a paragraph

Much of people behaviour can be explained by simplified, sometimes irrational, often automatic decision-making processes rather than careful rational thought. Many of these processes can be understood formally, if not scientifically, such understanding can be applied generally to good effect.


Structure of the book

Much of the book is coached in the terms of the “habit-loop” a form of conditioning which can be observed in the brains of humans and animals.

The book starts off by investigation the evidence for this habit-loop at a physiogical level and looks at its implications. It then attempts to apply this idea rather loosely to a number of other fields: organizations, social movements and medical treatment. However, since these formally constrained ideas cannot be cleanly applied to these fields (or even individual human behaviour) it becomes more of an anecdote filled discovery of how the more general theme of automatic behaviour can be applied to these fields.

September 16, 2012 at 8:29 pm Leave a comment

One of the nice thing about reading books on kindle is your ability to take

One of the nice thing about reading books on kindle is your ability to take notes as you read in a way that doesn’t despoil a book. Another advantage of having electronic notes is that you can do interesting things with them (in my case I’m feeding them into anki).

Exporting kindle notes

The easiest way I found to export notes from a kindle (particular from a phone acting as a kindle was via the annotations website:

https://kindle.amazon.com/your_highlights.

This unfortunately lacks the exact location of the note but is good enough for many use cases.

Better ways to export

This was good enough for me though I didn’t go further. The more paranoid impulses in me say that I should be liberating as much of my data as possible in case kindle decides to destroy it – but I decided I was happy in the knowledge that this could be done, and trust that someone will start complaining if amazon decides to stop letting you do this in good time for me to react.

In case this is the use case you are after or you have more advanced uses for your highlights then there were a couple of approaches I came across on the internet, but didn’t use:

  • There appears to be a PERL script to do this for you
  • The read.amazon.com site looks like it would be very easy to scrape.
  • kindle readers supposedly

August 30, 2012 at 9:26 pm Leave a comment

Samsung Galaxy S2 i9100 over-heating battery symbol fix (Probably water related)

It turns out that phones don’t like water (even rain). After a particularly heavy rain shower, my phone developed a strange behavior where it would show a battery symbol together with a hot thermometer and refuse to switch on. This fixed itself after 10 minutes or so, but some time later the similar symptoms reappeared.

  • The phone ran fine when on
  • When switched off the phone refused to switch on (with aforementioned over-heating battery symbol)
  • However, when the micro-usb had a power source plugged in everything worked fine.

It seems like this is a common problem with the usb connector, and some people have fixed similar issues by buying replacement usb cards. Fortunately, I didn’t need to go so far, blowing compressed air into the micro-usb connector completely fixed this issue.

June 28, 2012 at 6:55 pm 3 comments

Ensure a bash process tidies up its children

When you have a bash process that spawns a number of background children, there is an unforunate side effect: These processes never exit. If you try to kill their parent they are happilly adopted by init.


Code

Adding the following line at the beginning of your bash script ensure that all your children are truly dead when you yourself are killed.

trap "kill -- -$BASHPID" EXIT

The -PID argument tells bash to kill the process group with id $BASHPID, process groups have the same id as the spawning process (but the process group id remains even after processes have been reparented). The — gets kill not to interpret this as a signal :S.


Caveats

The one caveat here is if someone sends you kill -9. If this happens, you don’t get to do anything before your imminent death (even murder all your children).

June 22, 2012 at 2:56 pm Leave a comment

Showing the build dependencies of an apt package

apt-cache showsrc name

March 4, 2012 at 11:39 pm Leave a comment

Turning your computer into a wireless router – easy-to-run code.

The following script adapted from this post https://exain.wordpress.com/2011/03/31/making-a-wifi-hotspot-access-point-using-linux-wifi-lan-cardusb-adapter/ will an ubuntu linux laptop with a wireless dongle into a wireless router:

https://github.com/argandgahandapandpa/computer-router

You need to run sudo bash start.sh and sudo bash stop.sh to start and stop the script, and create a local settings file to store your configuration.

November 26, 2011 at 7:17 pm Leave a comment

Monitoring processes – hurrah for supervisord (maybe)

Monitoring processes, recording their output, and restarting them when they are exit is a common task and quite a fiddlesome and time-consuming one at that. Therefore it makes sense to use a shared code for this task, rather than rolling your own code repeatedly. There are a few solutions for this: upstart and supervisord being two candidates.

In using such shared code you are entering into the world of frameworks (code that you write configuration for, which then calls into your code, rather than APIs that you call into yourself). Frameworks have some risks associated with them:

* Hitting a brick wall where they can’t be made to do what you want to do (extending them is then difficult)
* Having a domain specific configuration language that makes performing tasks harder than it would be to just write all the code yourself in a language that you already know (either due to fixed or variable costs)
* Being difficult to debug (because they solve general problems)

=== Experiences with upstart ===

My experiences with upstart have not been too rosy. This is mainly because because failure mode is largely “your process exitted”. You are made responsible for logging your own output. This is all well and good, until you find that the command line itself is erroring out and you have no output. The obvious work around for this is to make your upstart scripts as simple as possible and push everything into separate jobs that are guaranteed to log output – but this loses some of the features of upstart. The other disturbing things is that these other jobs have to run as root!

It’s also a bit of pain having to do everything on a system level. I prefer not to be root too much of my time, and I like to be able to run multiple copies of things.

The reason for these problems is not so much that upstart is badly designed (though features like capturing all your output or telling you what is wrong with your configuration file wouldn’t go amiss), but that upstart is designed to handle a different task – being robust, never erroring out, handling events and handling a lot of processes. The debug output for complicated chains of events seems to be quite good for example

=== Supervisord to the rescue ===

Supervisord’s purpose is a lot more restrictive and more closely aligned with what I am often trying to do – just monitor some processes. It seems to do this quite well having a few nice features:

* Automatically capturing output!
* Not requiring to be run as root
* Minimal configurations

There are a few losses however compared to upstart. It doesn’t really support the whole starting daemons in response to events thing that upstart has. It does have a notion of events, but these are fed out to specially written listeners rather than being fed back into the configuration files.

Further, I don’t really know how stable supervisord is, upstart will have had many obscure bugs fixed since it is run all the time on millions of machines… this isn’t really the case with supervisord.

November 26, 2011 at 3:21 pm Leave a comment

Working around networkmanager wireless problems

After upgrading to ubuntu 11.10 I had a few a problems with wireless internet on network manager

* Networkmanager failed to turn wireless back on if it was switched off until the machine was restarted.
* Gnome shells network manager applet is (deliberately) broken and doesn’t allow you to disconnect from a wireless network.

All in all this is quite irritating, as a horrible work around you can use nmcli to manage your connections.

nmcli conn list — shows you all connections
nmcli conn down uuid UUID — takes down the connection

November 17, 2011 at 11:30 pm Leave a comment

R plot a number of graphs on the same plot with different colours

plot(xs, y1s, col=”red”)
points(xs, y2s, col=”blue”)

November 15, 2011 at 4:48 pm Leave a comment

Older Posts


May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031