Skip to content

Instantly share code, notes, and snippets.

@jsatk
Last active August 29, 2015 13:57
Show Gist options
  • Save jsatk/9608566 to your computer and use it in GitHub Desktop.
Save jsatk/9608566 to your computer and use it in GitHub Desktop.
Replaces your clipboard with an underscore delimited string. Throw in your ~/Library/Scripts/ directory and `chmod a+x`.
#!/usr/bin/ruby
# Save file to a directory in your $PATH.
# Ensure it is executable `chmod a+x clipboard_manipulation.rb`.
#
# Usage `copy some text like this`.
# Then from the commandline run `clipboard_manipulation.rb space underscore`.
# Your clipborad will now contain the text `copy_some_text_like_this`.
#
# This is a simply and silly script that scratched an itch I was having.
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
end
def pbpaste
`pbpaste`
end
types = {
comma: ', ',
dash: '-',
decimal: '.',
period: '. ',
space: ' ',
underscore: '_'
}
from = ARGV[0].to_sym
to = ARGV[1].to_sym
return 'Not valid `from`' unless types.key?(from)
return 'Not valid `to`' unless types.key?(to)
pbcopy(pbpaste.gsub(types[from], types[to]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment