Jay McGavren's Journal

2008-12-27

~/bin

OK, just finished porting my toolbox to OS X. I’ve gotten rid of all those dumb text files and generators, as they were really only needed under Windows.

I ported some stuff to take advantage of my Ruby utilities library, and threw out a lot of cruft. Here’s what made the cut…

am

#!/bin/sh
twtr up -m "$1"

append

#!/usr/bin/ruby
require 'utility'

puts Util.new.get_piped_data.append(ARGV.join(' '))

clipboard

#!/usr/bin/ruby
require 'utility'

input = Util.new.get_piped_data
if input
  IO.popen('pbcopy', 'w').print(input)
else
  puts `pbpaste`
end

date

#!/usr/bin/ruby
require 'utility/enhancements'
puts Time.new.format_date

date_time

#!/usr/bin/ruby
require 'utility/enhancements'
puts Time.new.format

define

#!/bin/bash
open http://dictionary.reference.com/search?q=$(echo $@ | sed 's/ /+/g')

delete

#!/usr/bin/ruby
require 'utility'

util = Util.new
storage = util.load(:storage)
storage.delete(ARGV.join(' '))
util.save(:storage, storage)

email

#!/usr/bin/ruby

require 'utility'

util = Util.new
util.parse_rfc822(util.get_piped_data).send

event

#!/usr/bin/ruby
require 'utility'

file = File.open(File.join(ENV['HOME'], "events.txt"), "a")
file.puts "#{Time.new.format}t#{ARGV.join(' ')}"

find_movie

#!/bin/bash
open "http://www.netflix.com/Search?v1=$(echo $@ | sed 's/ /+/g')"

find_show

#!/bin/bash
open "http://www3.tivo.com/tivo-tco/search.do?searchFor=$(echo $@ | sed 's/ /+/g')&dispatch=simplesearch&searchCategory=&x=0&y=0"

get

#!/bin/bash
scp -r $@ ~/Downloads

group_rename

#!/usr/bin/ruby

require 'utility'
require 'fileutils'

#Get options.
usage = "Usage: group_rename.rb expression filesn"
expression = ARGV.empty? ? raise(usage) : ARGV.shift
globs = ARGV.empty? ? raise(usage) : ARGV

#For each file in expanded globs:
globs.each do |glob|
	Dir.glob(glob).each do |path|
		#Evaluate the expression.
		new_path = eval "path.#{expression}"
		#If the resulting filename is identical to the current filename, skip it.
		next if path == new_path
		#If filenames differ only in case, move it to temp file first.
		if path.downcase == new_path.downcase
			FileUtils.mv(path, path + ".tmp")
			FileUtils.mv(path + ".tmp", new_path)
		#Otherwise, simply move file.
		else
			FileUtils.mv(path, new_path)
		end
	end
end

indent_xml

#!/usr/bin/ruby

require 'utility'

puts Util.new.get_piped_data.indent_xml

interpolate

#!/usr/bin/ruby

require 'utility/all'

print Util.new.get_piped_data.interpolate

list

#!/usr/bin/ruby
require 'utility'

util = Util.new
print util.load(:storage).keys.sort.join("n")

load

#!/usr/bin/ruby
require 'utility'

util = Util.new
print util.load(:storage)[ARGV.join(' ')]

locate

#!/bin/bash
open "http://local.google.com/local?q=$(echo $@ | sed 's/ /+/g')&near=[my+address]"

lower_case

#!/usr/bin/ruby

STDIN.each{|l| puts l.downcase}

newsgroup

#!/bin/bash
open "http://groups.google.com/group/$(echo $@ | sed 's/ /+/g')"

nohup.out



note

#!/usr/bin/ruby

require 'utility'

util = Util.new
Utility::Email::Email.new(
	:senders => [util.load(:home_email)],
	:recipients => [util.load(:home_email)],
	:subject => "Note: #{ARGV.join(' ')}",
	:body => util.get_piped_data
).send

one_line

#!/usr/bin/ruby
require 'utility'

puts Util.new.get_piped_data.one_line

prepend

#!/usr/bin/ruby
require 'utility'
puts Util.new.get_piped_data.prepend(ARGV.join(' '))

quote

#!/bin/bash
wrap 60 | prepend "> "

reminder

#!/usr/bin/ruby

require 'utility'

util = Util.new
Utility::Email::Email.new(
	:senders => [util.load(:home_email)],
	:recipients => [util.load(:home_email)],
	:subject => "Reminder: #{ARGV.join(' ')}",
	:body => util.get_piped_data
).send

rgrep

#!/bin/bash
find "$2" -type f -exec grep --with-filename "$1" "{}" ;

run_erb

#!/usr/bin/ruby
require 'utility'

print Util.new.get_piped_data.run_erb

save

#!/usr/bin/ruby
require 'utility'

util = Util.new
storage = util.load(:storage) || {}
storage[ARGV.join(' ')] = util.get_piped_data
util.save(:storage, storage)

search

#!/bin/bash
open http://www.google.com/search?q=$(echo $@ | sed 's/ /+/g')&num=100

search_code

#!/bin/bash
open http://www.google.com/codesearch?as_q=$(echo $@ | sed 's/ /+/g')&num=100

shop

#!/bin/bash
open http://froogle.google.com/froogle?q=$(echo $@ | sed 's/ /+/g')&num=100

shorthand

#!/usr/bin/ruby
require 'utility'
print Util.new.get_piped_data.shorthand

split_into

#!/bin/bash
#Splits a file into X-byte chunks.
#Usage: split_into nnn[k|m] file
split -b$1 $2 $2

subfolders_by_exif_date

#!/usr/bin/ruby

require 'fileutils'
require 'exifr'

ARGV.each do |file|
	begin
		date = EXIFR::JPEG.new(file).date_time_original
		dir = sprintf('%04d-%02d-%02d', date.year, date.month, date.mday)
		Dir.mkdir(dir) unless File.exist?(dir)
		FileUtils.mv(file, dir)
	rescue => exception
		abort "Error processing #{file}: " + exception.message + "n" + exception.backtrace.join("n")
	end
end

upper_case

#!/usr/bin/ruby

STDIN.each{|l| puts l.upcase}

utility

#!/bin/sh
ruby -rutility -e "$1"

wikipedia

#!/bin/bash
open http://en.wikipedia.org/wiki/Special:Search?search=$(echo $@ | sed 's/ /+/g')

work_note

#!/usr/bin/ruby

require 'utility'

util = Util.new
Utility::Email::Email.new(
	:senders => [util.load(:home_email)],
	:recipients => [util.load(:work_email)],
	:subject => "Note: #{ARGV.join(' ')}",
	:body => util.get_piped_data
).send

work_reminder

#!/usr/bin/ruby

require 'utility'

util = Util.new
Utility::Email::Email.new(
	:senders => [util.load(:home_email)],
	:recipients => [util.load(:work_email)],
	:subject => "Reminder: #{ARGV.join(' ')}",
	:body => util.get_piped_data
).send

wrap

#!/opt/local/bin/perl

#Get command line options.
$wrap_column = $ARGV[0] || 60;

#Set up text wrap options.
use Text::Wrap;
use Text::Tabs;
$Text::Wrap::columns = $wrap_column;

#Process each input line.
LINE: while () {

	#Clean up line.
	chomp;

	#Get existing indentation to use on subsequent lines.
	if (/^(s+)/) {$indentation = $1}
	else {$indentation = undef}

	#Wrap text and print.
	print expand(wrap(undef, $indentation, $_)) . "n";

}

zyps_download_count

#!/bin/bash
curl --silent http://gems.rubyforge.org/stats.html | grep zyps
comments powered by Disqus