Skip to content

Instantly share code, notes, and snippets.

@kaosf
Last active April 6, 2017 10:24
Show Gist options
  • Save kaosf/6217906 to your computer and use it in GitHub Desktop.
Save kaosf/6217906 to your computer and use it in GitHub Desktop.
"autohash"; earthquake.gem's plugin; add hash tags to the tails of a tweet automatically; ref. https://github.com/kaosf/earthquake-plugin-autohash
class HashTagsManager
def filepath
"#{ENV['HOME']}/.earthquake/autohash"
end
def save(hashtags)
File.open filepath, 'w' do |f|
f.puts hashtags
end
end
def get
hash_str = ""
if File.exist? filepath
File.open filepath do |f|
f.each_line do |l|
l.chomp!
l.gsub! /^#*/, ''
hash_str += " ##{l}"
end
end
end
hash_str
end
def reset
File.delete filepath if File.exist? filepath
end
end
if Object.const_defined? :Earthquake
Earthquake.init do
h = HashTagsManager.new
command :autohash do
h.reset
end
command :autohash do |m|
h.save m[1].split("\s")
end
command %r|^[^:\$].*| do |m|
input(":update #{m[0]}#{h.get}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment