Last active
August 31, 2020 10:06
-
-
Save mieko/7ae96382bf17cffb3eb2d862d2128d8e to your computer and use it in GitHub Desktop.
Shell functions that always remember to type `./bin/rails` when you type `rails`
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
# Tries to find a parent directory containing a file: "$1" | |
find-up() { | |
local path=$(pwd) | |
while [[ -n "$path" && ! -e "$path/$1" ]]; do | |
path=${path%/*} | |
done | |
echo "$path" | |
} | |
try-binstub() { | |
local cmd="$1"; | |
shift; | |
local rails_dir="$(find-up Gemfile)" | |
if [[ -n "$rails_dir" && -x "$rails_dir/bin/$cmd" ]]; then | |
"$rails_dir/bin/$cmd" "$@" | |
else | |
command "$cmd" "$@" | |
fi | |
} | |
rails() { | |
try-binstub "rails" "$@" | |
} | |
rspec() { | |
try-binstub "rspec" "$@" | |
} | |
rake() { | |
try-binstub "rake" "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment