Saturday, January 14, 2012

Vim Script, redux.

So if you tried using the script (you didn't, but if you HAD) on Windows, you would have discovered pretty quickly that it was terribly bugged.
I forgot git has its own Cygwinified shell when in Windows, so calling git from subprocess is going to bomb spectacularly.

What's worse, is since the git shell isn't really git, but a bash shell (ok ok Cygwin), you can't just pass a "git clone" argument anywhere easily.
You can, however, pass a shell script to auto-execute like any bash shell.
So, I made a few changes to the script.

It now has this function:
def call_git_windows(gitUrl):
    TEMP_FILE_PATH = os.path.expanduser('~\\vimfiles\\')
    # default git path
    path = os.path.join('C:', '\Program Files (x86)', 'Git', 'bin', 'sh.exe')
    tmp =, os.O_WRONLY|os.O_CREAT)
    print tmp
    os.write(tmp, ' '.join(['git clone', gitUrl]))
    cmd = ' '.join([path, '--login', '-i', TEMP_FILE_PATH])
    print cmd

It's pretty basic.
The major deficiencies are the hard coded git path (I looked, lazily, for an ENV variable that had it) and the hard coded TEMP_FILE_PATH.
They are both really "sensible defaults" and should probably be treated as such, abstracting into the function method signature or in a conf file when I expand the functionality to support saving a history of commands.

Next steps are tracking the installs in a pickle file, tying a config file to the process, and creating an alias.
Then there's just deployment testing.
I should write some unit tests for the thing too, once it graduates from "toy program" to "useful tool".
Maybe next weekend; babies are hard.

No comments:

Post a Comment