Skip to content

Instantly share code, notes, and snippets.

@ejangi
Created December 31, 2013 06:44
Show Gist options
  • Save ejangi/8193443 to your computer and use it in GitHub Desktop.
Save ejangi/8193443 to your computer and use it in GitHub Desktop.
This is a OS X command line tool I keep in my $PATH to quickly Fix titles when copy/pasting for blog posts etc.
#!/usr/bin/env ruby
options = Array.new
string = String.new
titlized = String.new
pbcopy = "cbcopy"
if RUBY_PLATFORM =~ /darwin/ then
pbcopy = "pbcopy"
end
ARGV.each do|a|
if a[0,1] == '-' then
options << a
else
string = a
end
end
if string.empty? then
puts "You must provide a string to transform"
exit
end
if options.include? '-d' or options.include? '-l' or options.include? '--downcase' or options.include? '--lowercase' then
titlized = string.downcase
elsif options.include? '-u' or options.include? '--uppercase' then
titlized = string.upcase
elsif options.include? '-b' or options.include? '--bumpy' then
titlized = string.split(/\s+/).each{ |word| word.capitalize! }.join(' ')
elsif options.include? '-p' or options.include? '--permalink' then
titlized = string.downcase.gsub(/\b+/, " ").gsub(/[^a-z0-9\s]+/i, '').strip.gsub(/\s+/, '-')
else
titlized = string.capitalize
end
if !titlized.empty? then
puts titlized
IO.popen(pbcopy, 'w+') {|clipboard| clipboard.write(titlized)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment