Last active
December 29, 2015 14:39
-
-
Save h14i/7685140 to your computer and use it in GitHub Desktop.
contextual rails wrapper script for zsh.
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
# contextual - wrapper of (spring|bundle exec) commands. | |
# usage: | |
# # in zshrc | |
# source /path/to/contextual | |
# alias rails=contextual-rails | |
# alias rake=contextual-rake | |
# alias rspec=contextual-rspec | |
# completion: | |
# # in zshrc | |
# # require https://github.com/zsh-users/zsh-completions/src/_rails | |
# compdef _rails contextual-rails | |
function with-spring { | |
$(type spring &> /dev/null) && [[ -x bin/$1 ]] | |
} | |
function with-bundler { | |
$(type bundle &>/dev/null) && [[ -x bin/bundle ]] | |
} | |
function contextual { | |
local cmd | |
cmd=$1; shift | |
if with-spring $cmd; then | |
print "spring $cmd $@" | |
command spring $cmd $@ | |
elif with-bundler ; then | |
print "bundle exec $cmd $@" | |
command bundle exec $cmd $@ | |
else | |
print "naked $cmd $@" | |
command $cmd $@ | |
fi | |
} | |
function contextual-rake { | |
contextual rake $@ | |
} | |
function contextual-rails { | |
contextual rails $@ | |
} | |
function contextual-rspec { | |
contextual rspec $@ | |
} | |
# vim:set ft=zsh: |
usageのtypoを修正する。contextualってtypoしやすいよな…。でもsmartとかcleverはイマイチしっくり来ないので…。
コメントでTODOをメモするのどうなのよ?あとでcleanupする。
あとautoloadで動くように。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IFS設定のタイミングがおかしいのをあとで修正する。コマンドから関数へ変えたときに直し忘れたっぽい。