Last active
August 29, 2015 13:57
-
-
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`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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