From 88172666986691c1d81b6166b481f92fc1298795 Mon Sep 17 00:00:00 2001 From: Kevin Bongart Date: Tue, 1 Jul 2014 10:26:32 -0400 Subject: [PATCH] Prepend "rails", "rake" and "rspec" commands with "spring" when possible --- plugins/spring/spring.plugin.zsh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 plugins/spring/spring.plugin.zsh diff --git a/plugins/spring/spring.plugin.zsh b/plugins/spring/spring.plugin.zsh new file mode 100644 index 000000000..13cb84a06 --- /dev/null +++ b/plugins/spring/spring.plugin.zsh @@ -0,0 +1,31 @@ +spring_commands=(rails rake rspec) + +_spring_installed() { + which spring > /dev/null 2>&1 +} + +_within_springified_rails_project() { + local check_dir=$PWD + while [ $check_dir != "/" ]; do + [ -f "$check_dir/bin/spring" ] && return + check_dir="$(dirname $check_dir)" + done + false +} + +_run_with_spring() { + if _spring_installed && _within_springified_rails_project; then + spring $@ + else + $@ + fi +} + +for cmd in $spring_commands; do + eval "function springified_$cmd () { _run_with_spring $cmd \$@}" + alias $cmd=springified_$cmd + + if which _$cmd > /dev/null 2>&1; then + compdef _$cmd springified_$cmd=$cmd + fi +done