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 Nov 27, 2013

実行する前にprintしてるのは僕の好みというか何というか。(何が実行されてるのか見えないと不安じゃないですか?)

@h14i
Copy link
Author

h14i commented Dec 2, 2013

同じアプローチでrake版とrspec版もある。ほとんどコード一緒。
シェルスクリプトじゃなくてシェル関数にしてしまったほうが良いんだろうか。そのほうがリファクタリングしやすいし。

@h14i
Copy link
Author

h14i commented Dec 2, 2013

あとでリファクタリングする。

@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