Skip to content

Instantly share code, notes, and snippets.

@h14i
Last active December 29, 2015 14:39
Show Gist options
  • Save h14i/7685140 to your computer and use it in GitHub Desktop.
Save h14i/7685140 to your computer and use it in GitHub Desktop.
contextual rails wrapper script for zsh.
# 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:
@h14i
Copy link
Author

h14i commented Dec 12, 2013

IFS設定のタイミングがおかしいのをあとで修正する。コマンドから関数へ変えたときに直し忘れたっぽい。

@h14i
Copy link
Author

h14i commented Dec 12, 2013

usageのtypoを修正する。contextualってtypoしやすいよな…。でもsmartとかcleverはイマイチしっくり来ないので…。

@h14i
Copy link
Author

h14i commented Dec 13, 2013

コメントでTODOをメモするのどうなのよ?あとでcleanupする。
あとautoloadで動くように。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment