Created
March 21, 2013 03:07
-
-
Save derdesign/5210400 to your computer and use it in GitHub Desktop.
Create vim project files that open automatically with MacVim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var fs = require('fs'); | |
var util = require('util'); | |
var pathmod = require('path'); | |
var EXTENSION = 'vimproj'; | |
var EXT_REGEX = new RegExp('\\.' + EXTENSION + '$'); | |
var TEMPLATE = '\ | |
#!/usr/bin/env node\n\ | |
process.chdir("{PATH}");\n\ | |
require("child_process").spawn("mvim", ["."]);\n\ | |
process.exit();'; | |
function main() { | |
var args = process.argv.slice(2); | |
switch (args.length) { | |
case 2: | |
var cwd = process.cwd(); | |
var path = pathmod.resolve(cwd, args[0]); | |
var proj, projfile, target = pathmod.resolve(cwd, args[1]); | |
// Get project file and target path | |
if (EXT_REGEX.test(target)) { | |
proj = pathmod.dirname(target); | |
projfile = target; | |
} else { | |
proj = target; | |
projfile = util.format("%s/%s.%s", proj, pathmod.basename(path), EXTENSION); | |
} | |
// Bail if project path doesn't exist | |
if (!fs.existsSync(path)) { | |
console.log("Project path does not exist"); | |
process.exit(); | |
} | |
// Bail if target path does not exist | |
if (!fs.existsSync(proj)) { | |
console.log("Output path does not exist"); | |
process.exit(); | |
} | |
// Bail if output project file exists | |
if (fs.existsSync(projfile)) { | |
console.log("Project file already exists: " + projfile); | |
process.exit(); | |
} | |
var buf = TEMPLATE.replace("{PATH}", path); | |
console.log(util.format("Writing %s", projfile)); | |
fs.writeFileSync(projfile, buf, 'utf8'); | |
fs.chmodSync(projfile, 0755); | |
break; | |
default: | |
console.log("\nUsage: vimproject <path> <output-path>\n"); | |
process.exit(); | |
break; | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation Instructions
$PATH
After you create your first project, right click on it and set it to open with Terminal.app. This will automatically open MacVim when you double click on the directories you specify.
Usage:
The following creates
project.vimproj
on the current directoryThe following creates
myproject.vimproj
: