Created
July 15, 2017 18:37
-
-
Save mvalipour/80071a63125776bd75e6fbb0a0693856 to your computer and use it in GitHub Desktop.
Hacky code to generate new file based on text selection in atom
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
toSnakeCase = s => s.replace(/(?:^|\.?)([A-Z])/g, (x,y) => "_" + y.toLowerCase()).replace(/^_/, "") | |
editor = atom.workspace.getActiveTextEditor(); | |
path = editor.getPath(); | |
fileName = editor.getFileName(); | |
fileExt = fileName.split('.').pop(); | |
dir = path.substring(0, path.length - fileName.length); | |
selectedText = editor.getSelectedText(); | |
newPath = dir + toSnakeCase(selectedText) + '.' + fileExt; | |
atom.workspace.open().then(e => e.saveAs(newPath)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment