$ cat t.sh
#!/bin/bash
for func in guard rspec rake; do
eval "
${func}() {
local foo=(command ${func})
[ -e 'Gemfile' ] && foo=(bundle exec ${func})
\"\${foo[@]}\" \"\$@\"
}
"
done
type guard rspec rake
.
$ ./t.sh
guard is a function
guard ()
{
local foo=(command guard);
[ -e 'Gemfile' ] && foo=(bundle exec guard);
"${foo[@]}" "$@"
}
rspec is a function
rspec ()
{
local foo=(command rspec);
[ -e 'Gemfile' ] && foo=(bundle exec rspec);
"${foo[@]}" "$@"
}
rake is a function
rake ()
{
local foo=(command rake);
[ -e 'Gemfile' ] && foo=(bundle exec rake);
"${foo[@]}" "$@"
}
The usual cautions about `eval` apply.