Skip to content

Instantly share code, notes, and snippets.

@h14i
Last active December 29, 2015 14:39
Show Gist options
  • Select an option

  • Save h14i/7685140 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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