Skip to content

Instantly share code, notes, and snippets.

@blech
Last active February 13, 2019 20:07
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 blech/b7af4e9b24bc07c299b91c1072eb8b45 to your computer and use it in GitHub Desktop.
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
// 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