Skip to content

Instantly share code, notes, and snippets.

@jnothman
Created December 16, 2012 23:53
Show Gist options
  • Save jnothman/4314349 to your computer and use it in GitHub Desktop.
Save jnothman/4314349 to your computer and use it in GitHub Desktop.
This script renumbers an edited Opera Browser session file. If you remove some tabs/windows from an existing autosave.win (or other .win) file, the numbering becomes non-contiguous. Pipe the edited session file through this script and the numbering will now count from 1 to the required number of windows. However, you must also modify the 'window…
import re, sys
num_re = re.compile(r'(?<=^\[)[0-9]+')
in_n = ''
out_n = 0
def sub_cb(match):
global in_n, out_n
if match.group() != in_n:
in_n = match.group()
out_n += 1
return str(out_n)
for l in sys.stdin:
sys.stdout.write(num_re.sub(sub_cb, l))
print >> sys.stderr, 'change window count to:', out_n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment