Skip to content

Instantly share code, notes, and snippets.

@ejangi
Created December 31, 2013 06:50
Show Gist options
  • Save ejangi/8193481 to your computer and use it in GitHub Desktop.
Save ejangi/8193481 to your computer and use it in GitHub Desktop.
This is a OS X command line tool to create a permalink from a string
#!/usr/bin/env ruby
options = Array.new
string = String.new
permalink = 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
permalink = string.downcase.gsub(/\b+/, " ").gsub(/[^a-z0-9\s]+/i, '').strip.gsub(/\s+/, '-')
if !permalink.empty? then
puts permalink
IO.popen(pbcopy, 'w+') {|clipboard| clipboard.write(permalink)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment