A script used to properly paste contents from Kindle for Mac
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
help
.rvmrc
Gemfile
Gemfile.lock
README.md
kindle_fmt.rb

README.md

kindle-fmt

A simple ruby script which tries to properly format code blocks copied from the Kindle for Mac application. I was ramping up on android using a Kindle book and realized the app does a terrible job of copy/pasting contents to an IDE/text editor. This script reads the contents of your clipboard and applies some basic formatting logic then replaces the contents of your clipboard with (somewhat) better formatted code. Not perfect, but made my life a little easier.

Usage

1- Install clipboard gem:

gem install clipboard

2- Go to your Kindle app copy a block of code (only xml and java supported for now)

3- Run the kindle_fmt script from your terminal.

./kindle_fmt

4- The contents of your clipboard should contain newly formatted code.

Before After

Script will try to detect if you're pasting xml or java. You can explicitly tell the script how to treat the text. Ex:

./kindle_fmt xml

OR

./kindle_fmt java

Tips

  • To make your life easier, add the git repo folder to your path so you can run this from anywhere: (In ~/.bashrc or ~/.zshrc)

export PATH=$PATH:/path/to/kindle_fmt

  • You could probably bind this script to a hotkey combo to make life even easier. Kind of annoying having to go to the terminal to apply formatting.

TODO

  • Get Amazon to fix formatting int heir app. Its turrrrible.
  • My formatting rules are super basic and don't cover corner cases well at all. Feel free to improve.
  • Add support for more languages\syntax.