Last active
February 13, 2019 20:07
-
-
Save blech/b7af4e9b24bc07c299b91c1072eb8b45 to your computer and use it in GitHub Desktop.
Small BBEdit script to let me easily flip between React components and containers
This file contains hidden or 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
// paste into Script Editor, then save it into | |
// ~/Library/Application Support/BBEdit/Scripts | |
var bbedit = Application('BBEdit'); | |
bbedit.includeStandardAdditions = true | |
var src_path = bbedit.windows[0]().file() | |
// coerce to string, hackily | |
src_path = src_path+'' | |
var src_comp = src_path.split("/") | |
// flip around to get at -2 more easily, and change | |
src_comp.reverse() | |
if (src_comp[2] == "containers") { | |
src_comp[2] = "components"; | |
} else if (src_comp[2] == "components") { | |
src_comp[2] = "containers"; | |
} | |
// flip back, join, open | |
src_comp.reverse() | |
var new_path = src_comp.join('/') | |
// better error handling | |
try { | |
bbedit.open(new_path) | |
} catch(error) { | |
bbedit.displayAlert(`Error opening counterpart ${new_path}: ${error}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment