Created
August 22, 2017 19:58
-
-
Save ssddanbrown/efa84e515a552af1602911bb97a59d1e to your computer and use it in GitHub Desktop.
Sublime Text Project Manager Script
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 | |
// 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