Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

echo gets command substitution

seriously, how cool is that?

  > echo foo $(echo $(echo what) the hell)
  foo what the hell
  • Loading branch information...
commit 6a72ae3765476b67cf8d4c6ad5dc6ea7d1b73fc4 1 parent 6e9a102
@pbrisbin authored
Showing with 21 additions and 3 deletions.
  1. +21 −3 plugins/echo.rb
View
24 plugins/echo.rb
@@ -1,5 +1,23 @@
-Basil.respond_to(/^(echo|say) (.*)/) {
+# says will be a little cute with "I am"
+Basil.respond_to(/^say (.*)/) {
- says @match_data[2].strip.sub(/^basil\s+is\b/i, 'I am')
+ says @match_data[1].strip.sub(/^basil\s+is\b/i, 'I am')
-}.description = "echos what it's told"
+}.description = "says what it's told"
+
+# echo is more programmer-friendly and has command substitution
+Basil.respond_to(/^echo (.*)/) {
+
+ msg = @match_data[1].strip
+
+ # neat part is it'll do it recursively.
+ while msg =~ /(.*)\$\((.*)\)(.*)/
+ prefix = $1
+ suffix = $3
+ result = Basil.dispatch(Basil::Message.new(Basil::Config.me, nil, nil, $2)).text
+ msg = "#{prefix}#{result}#{suffix}"
+ end
+
+ says msg
+
+}.description = "says what it's told"
Please sign in to comment.
Something went wrong with that request. Please try again.