Last active
August 23, 2017 07:10
-
-
Save atzorvas/047b3733caa7635ebef7f02aa1300db0 to your computer and use it in GitHub Desktop.
beautify clipboard script w ruby/python/xclip
This file contains hidden or 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 | |
| # Requirements: xclip, python, ruby | |
| # | |
| # Copy your the json or ruby hash you wish to transform into a indented json | |
| # run the script (eg. with a hotkey), and then paste | |
| # | |
| # Handles: | |
| # * json | |
| # * ruby hash | |
| raise "please install xclip (or alter the script)" unless system("which xclip") | |
| raise "please install xclip (or alter the script)" unless system("which python") | |
| require 'json' | |
| clipboard_contents = %x{ xclip -o } | |
| begin | |
| system("echo '#{eval(clipboard_contents).to_json}' | python -c 'import sys,json;print json.dumps(json.load(sys.stdin),indent=2)' | xclip -selection clipboard") | |
| rescue | |
| system("xclip -o | python -c 'import sys,json;print json.dumps(json.load(sys.stdin),indent=2)' | xclip -selection clipboard") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment