Skip to content

Instantly share code, notes, and snippets.

@penguin2716
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penguin2716/8931669 to your computer and use it in GitHub Desktop.
Save penguin2716/8931669 to your computer and use it in GitHub Desktop.
投稿文字列の3文字以上のアルファベット文字列(internationalizationとか)を縮めて(i18nとか)ツイートするmikutterプラグイン
# -*- coding: utf-8 -*-
Plugin.create :shrink_words do
def shrink_words(src)
str = src
src.scan(/[a-zA-Z_]+/).map{ |s|
if s.size > 3
[s, s[0] + (s.size - 2).to_s + s[-1]]
else
[s, s]
end
}.each{ |pair|
str.sub!(pair[0], pair[1])
}
str
end
filter_gui_postbox_post do |gui_postbox|
src = Plugin.create(:gtk).widgetof(gui_postbox).widget_post.buffer.text
text = shrink_words(src)
Service.primary.post :message => text
Plugin.call(:before_postbox_post, text)
Plugin.create(:gtk).widgetof(gui_postbox).widget_post.buffer.text = ''
Plugin.filter_cancel!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment