Skip to content

Instantly share code, notes, and snippets.

@ssddanbrown
Created August 22, 2017 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssddanbrown/efa84e515a552af1602911bb97a59d1e to your computer and use it in GitHub Desktop.
Save ssddanbrown/efa84e515a552af1602911bb97a59d1e to your computer and use it in GitHub Desktop.
Sublime Text Project Manager Script
#!/usr/bin/env node
// Imports
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
// Config
const storeFolder = path.join(process.env.HOME, '.config/sublime-projects');
const sublimePath = '/opt/sublime_text/sublime_text'
let currentDir = process.cwd();
let dirName = path.basename(currentDir);
let projectName = dirName.toLowerCase().replace(/\s/g, '_');
let projectFile = path.join(storeFolder, projectName + '.sublime-project');
let sublimeCommand = `${sublimePath} --project ${projectFile}`
// Create project file if it does not exist
if (!fs.existsSync(projectFile)) {
fs.writeFileSync(projectFile, getProjectContent(currentDir), 'utf8');
}
// Run sublime
exec(sublimeCommand);
function getProjectContent(path) {
return `
{
"folders":
[
{
"path": "${path}"
}
]
}
`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment