Batch edit your PuTTY Sessions

The color that PuTTY uses for blue is simply too dark. The scrollback buffer, by default, is 200 lines. That's ridiculous, I have several gigabytes of RAM going to waste here. In case you have a lot of stored sessions, it's quite tiresome to use PuTTY to go through all of them and fix whatever settings you would like to change. You can edit them directly in the registry, though - or use this Python 3 script!

from winreg import OpenKey, EnumKey, QueryValueEx, SetValueEx, \
  KEY_WRITE, KEY_READ, HKEY_CURRENT_USER as HKCU

class callrange:      
    def __init__(self, call_function):
        self.call = call_function
    def __getitem__(self,index):
        try: return self.call(index)
        except OSError: raise IndexError

with OpenKey(HKCU,"SOFTWARE\SimonTatham\PuTTY\Sessions") as sessions:
    for s in callrange(lambda i: EnumKey(sessions,i)):
        with OpenKey(sessions,s,access=KEY_WRITE|KEY_READ) as key:
            for name,value in [
                ('Colour14','100,100,250'),
                ('Colour15','120,120,250'),
                ('TerminalType','xterm'),
                ('ScrollbackLines',6000)
            ]:
                type = QueryValueEx(key,name)[1]
                SetValueEx(key,name,0,type,value)

By the way, searching the tubes reveals some useful suggestions to improve PuTTY's default settings.

Leave a Reply

Your email address will not be published. Required fields are marked *