Skip to content

Instantly share code, notes, and snippets.

@tkeo
Forked from anonymous/cbhistory.rb
Created January 4, 2013 09:53
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 tkeo/4451323 to your computer and use it in GitHub Desktop.
Save tkeo/4451323 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
Dir.chdir
Dir.chdir(FileUtils.mkdir_p('cblog').last)
last_string = nil
loop do
sleep 1
string = IO.popen('pbpaste', 'r+') {|io| io.read }
next if string.nil? || string.empty? || string == last_string
filename = Time.now.strftime('%Y%m%d_%H%M%S_')
filename << string[0,8].gsub(/\W/, '_')
filename << '.txt'
File.open(filename, 'w') {|f| f.write(string) }
last_string = string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment