Skip to content

Instantly share code, notes, and snippets.

@mathieuravaux
Created March 18, 2011 01:12
Show Gist options
  • Save mathieuravaux/875462 to your computer and use it in GitHub Desktop.
Save mathieuravaux/875462 to your computer and use it in GitHub Desktop.
Fellow Noders - Rubyists, treat your muscle memory! `edit` will correctly use `bundle open` or `npm edit` whether `Gemfile.lock` or `package.json` are in the Git root.
function edit {
if [[ "$1" == "" ]]; then echo "usage: edit NAME (NAME is a bundled gem or npm package)"; return; fi
RES=$(git rev-parse --quiet --is-inside-work-tree 2>&1)
if [[ "$?" == "0" ]]; then
GIT_DIR=$(git rev-parse --show-toplevel)
if [[ -f "$GIT_DIR/package.json" ]]; then
npm edit $1
fi
if [[ -f "$GIT_DIR/Gemfile" ]]; then
bundle open $1
fi
else
echo "Error: not in a git working copy."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment