Skip to content

Instantly share code, notes, and snippets.

@sss
Forked from no6v/draft.rb
Created June 23, 2011 02:53
Show Gist options
  • Save sss/1041803 to your computer and use it in GitHub Desktop.
Save sss/1041803 to your computer and use it in GitHub Desktop.
module Earthquake::Input
def drafts
@drafts ||= []
end
end
Earthquake.init do
d = drafts
subcommands = {
apply: ->(index){Readline::HISTORY.push(d.at(Integer(index)))},
clear: -> {d.clear if confirm("Are you sure?", :n)},
delete:->(index){d.delete_at(Integer(index))},
exec: ->(index){input(d.delete_at(Integer(index)))},
list: -> {ap d},
save: ->(text) {d << text.lstrip},
}.with_indifferent_access
command %r|^:draft (#{Regexp.union(subcommands.keys)})(\s+.*)?$|o, :as => :draft do |m|
subcommand, arg = m.captures
subcommands[subcommand][*[arg].compact]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment