Skip to content

Instantly share code, notes, and snippets.

@foca
Created December 28, 2010 17:59
Show Gist options
  • Save foca/757486 to your computer and use it in GitHub Desktop.
Save foca/757486 to your computer and use it in GitHub Desktop.
if [ -x ~/.bash_completion.d/_transcript ]; then
complete -C ~/.bash_completion.d/_transcript -o default transcript
fi
#!/usr/bin/env ruby
# Save this somewhere, chmod 755 it, then add
# complete -C path/to/this/script -o default transcript
# to your ~/.bashrc
exit 0 unless /^transcript\b/ =~ ENV["COMP_LINE"]
TRANSCRIPTS_DIR = File.expand_path("~/Library/Application\ Support/Adium\ 2.0/Users/Default/Logs")
puts Dir[TRANSCRIPTS_DIR + "/*/#{$'.strip}*"].map {|buddy| File.basename(buddy) }.uniq
exit 0
#!/usr/bin/env ruby
require "nokogiri"
require "pathname"
require "time"
module Purple
TRANSCRIPTS_DIR = Pathname("~/Library/Application\ Support/Adium\ 2.0/Users/Default/Logs").expand_path
class Transcript
def self.all_files(buddy_name)
Dir.glob(TRANSCRIPTS_DIR.join("*/#{buddy_name}/**/*")).sort_by {|file| File.basename(file) }.select {|file| File.file?(file) }
end
def self.nth_last_file(buddy_name, which=-1)
all_files(buddy_name)[which]
end
def initialize(transcript)
@messages = Nokogiri(transcript).search("message")
end
def pretty_print(out=STDOUT)
@messages.each do |message|
out.print timestamp(message), " "
out.print nickname(message), " "
out.puts message.inner_text
end
end
def max_nickname_size
@max_nickname_size ||= @messages.map {|m| (m["alias"] || m["sender"]).size }.max
end
def nickname(message)
"<#{message["alias"] || message["sender"]}>".rjust(max_nickname_size + 2)
end
def timestamp(message)
"[" + Time.parse(message["time"]).strftime("%H:%M:%S") + "]"
end
end
end
if $0 == __FILE__
banner =<<-END_HELP
Usage: #{File.basename($0)} <buddy_name>
Display a nicely formatted Adium chat transcript to STDOUT. For example:
#{File.basename($0)} [email protected]
#{File.basename($0)} [email protected]
#{File.basename($0)} clever_aim_handle
This will get the latest (or currently active) chat transcript for the selected
buddy.
END_HELP
abort banner if ARGV.empty?
if ARGV[0] =~ /-\d+/
n = ARGV[0].to_i
buddy = ARGV[1]
else
n = -1
buddy = ARGV[0]
end
file = Purple::Transcript.nth_last_file(buddy, n)
abort "#{buddy} has no transcripts\n\n#{banner}" unless file && File.file?(file)
Purple::Transcript.new(File.read(file)).pretty_print
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment