Last active
April 6, 2017 10:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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