Skip to content

Instantly share code, notes, and snippets.

@navicore
Created February 2, 2014 18:01
Show Gist options
  • Save navicore/8772269 to your computer and use it in GitHub Desktop.
Save navicore/8772269 to your computer and use it in GitHub Desktop.
to unball a vim plugin
#!/usr/bin/python
#-*- coding:utf-8 -*-
# see http://forrst.com/posts/An_unball_script_for_vimball_plugins-CHM for
# author and credit of this code
import os, sys
if len(sys.argv) < 2:
raise SystemExit('Please specify a vba file (and optionally the directory to unball it to)')
infile = sys.argv[1]
vba_dir = os.path.splitext(infile)[0]
if len(sys.argv) > 2:
vba_dir = sys.argv[2]
if os.path.exists(vba_dir):
raise SystemExit('The location ' + vba_dir + ' already exists. Please delete/move it or give a different folder to extract into.')
lines = open(infile).read().splitlines()
vbasize = len(lines)
i = 0
while i < vbasize:
line = lines[i]
if line.endswith('\t[[[1'):
path = line.rstrip('\t[[[1').replace('\\', '/')
size = int(lines[i + 1])
content = '\n'.join(lines[i + 2 : i + 2 + size])
relpath = os.path.join(vba_dir, path)
dirname = os.path.dirname(relpath)
if not os.path.exists(dirname):
os.makedirs(dirname)
open(relpath, 'w').write(content)
print 'wrote', path
i += 2 + size
else:
i += 1
print 'Unballed', infile, 'into', vba_dir
print 'And hence the world rests in peace'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment