├── LICENSE ├── README.md ├── spaceman-diff ├── spaceman-diff-test.sh ├── test └── images │ ├── flag.png │ ├── gooder-flag.png │ ├── small-image.png │ └── with spaces.png └── tests /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Zach Holman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spaceman-diff 2 | 3 | diff images from the command line 4 | 5 | ![](https://cloud.githubusercontent.com/assets/2723/3005174/e28c2e00-ddd1-11e3-9dd8-c2c150e0ac86.jpg) 6 | 7 | ## what's inside™ 8 | 9 | Important business programmers don't have time to switch away from their terminal to view the diff of an image they're about to commit. The three seconds it takes to open an external diff visualization program could drive your sales team to drink and make inappropriate remarks to your new employees. Increase your productivity bottom line today, with `spaceman-diff`! 10 | 11 | `spaceman-diff` is a quick drop in to `git-diff`. The idea is that you can just `git diff` like normal and, if you've changed an image file, `spaceman-diff` will render your images in a colorful ASCII approximation in your shell along with helpful data like file size changes. 12 | 13 | Here's a quick example of what you might see: 14 | 15 | ![spaceman screenshot](https://user-images.githubusercontent.com/5113/51319639-e9e6ab80-1a5d-11e9-9cfe-ec0ea731ccde.png) 16 | 17 | The goal is that `spaceman-diff` gives you a quick way of verifying that yes, the image you're committing is the image you want to commit, and yes, the image you're committing isn't accidentally 20 terabytes in size or something foolish like that. 18 | 19 | Note: right now, spaceman-diff requires a *change* in the image; you won't see a diff rendered if you're simply adding or removing a file to your repo. `git diff` apparently doesn't pass things through to spaceman-diff at all in this case. There's probably a way to handle this, so pull requests accepted. 20 | 21 | ## dependencies 22 | 23 | There are two dependencies that you need before you can fiddle with pixels and characters and junk: [jp2a][jp2a] and [ImageMagick][imagemagick]. `jp2a` handles conversion of a JPEG to ASCII, and ImageMagick can do everything from image conversion to probably running a nuclear reactor. 24 | 25 | ### os x 26 | 27 | If you're using [Homebrew][brew], blindly run this: 28 | 29 | brew install jp2a imagemagick 30 | 31 | ### linux 32 | 33 | If you're using `apt`, you should be able to install your dependencies in a similar manner: 34 | 35 | sudo apt-get install jp2a imagemagick 36 | 37 | ## install 38 | 39 | Once you have your dependencies installed, drop [`spaceman-diff`][binary] onto your system or your dotfiles directory or whatever kooky stuff you're using. If you're using [Homebrew](http://brew.sh), you can instead install `spaceman-diff` with `brew install spaceman-diff`. After that, you need to configure Git to use `spaceman-diff` for all your image diffs. 40 | 41 | If you don't have one already, create a file at `~/.config/git/attributes` and add this to it: 42 | 43 | ```txt 44 | *.png diff=spaceman-diff 45 | *.jpg diff=spaceman-diff 46 | *.jpeg diff=spaceman-diff 47 | *.gif diff=spaceman-diff 48 | ``` 49 | 50 | This basically tells Git to use the `spaceman-diff` strategy to render the diff for these four particular file extensions. 51 | 52 | Next, you need to tell Git about spaceman-diff. Do that by editing `~/.gitconfig`: 53 | 54 | ```txt 55 | [diff "spaceman-diff"] 56 | command = /path/to/spaceman-diff 57 | ``` 58 | 59 | At this point, you should be ready to go. Try it out on a directory with an unstaged image change and run it with `git diff`. 60 | 61 | ## contributing 62 | 63 | [Send a pull request][pull] with your changes, and make sure the tests pass. You can run dem tests with `./tests` in your working directory. 64 | 65 | ## cool 66 | 67 | This was cobbled together by [@holman](https://twitter.com/holman). 68 | 69 | [jp2a]: https://csl.name/jp2a/ 70 | [imagemagick]: http://www.imagemagick.org 71 | [brew]: http://brew.sh 72 | [binary]: https://github.com/holman/spaceman-diff/blob/master/spaceman-diff 73 | [pull]: https://github.com/holman/spaceman-diff/pull/new/master 74 | -------------------------------------------------------------------------------- /spaceman-diff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # spaceman-diff 4 | # ...because you're too busy to leave the command line, dammit. 5 | # 6 | # Enjoy. 7 | 8 | set -e 9 | 10 | help() 11 | { 12 | cat < "$output_file" 10 | echo "$output_file" 11 | } 12 | 13 | it_shows_help_with_no_argv() { 14 | $spaceman | grep USAGE 15 | } 16 | 17 | it_renders_diff() { 18 | output_file=$(run_spaceman \ 19 | test/images/flag.png \ 20 | test/images/flag.png a190ba 100644 \ 21 | test/images/gooder-flag.png 000000 100644) 22 | 23 | grep -F "OLD: test/images/flag.png (2000x1263 px @ 84 KB)" < "$output_file" 24 | grep -F "NEW: test/images/gooder-flag.png (2000x1236 px @ 9 KB)" < "$output_file" 25 | 26 | rm "$output_file" 27 | } 28 | 29 | it_works_with_output_filenames_containing_spaces() { 30 | output_file=$(run_spaceman \ 31 | "test/images/flag.png" \ 32 | "test/images/flag.png" a190ba 100644 \ 33 | "test/images/with spaces.png" 000000 100644) 34 | 35 | grep -F 'OLD: test/images/flag.png (2000x1263 px @ 84 KB)' < "$output_file" 36 | grep -F 'NEW: test/images/with spaces.png (2000x1236 px @ 9 KB)' < "$output_file" 37 | 38 | rm "$output_file" 39 | } 40 | 41 | it_works_with_input_filenames_containing_spaces() { 42 | output_file=$(run_spaceman \ 43 | "test/images/with spaces.png" \ 44 | "test/images/with spaces.png" a190ba 100644 \ 45 | "test/images/flag.png" 000000 100644) 46 | 47 | grep -F 'OLD: test/images/with spaces.png (2000x1236 px @ 9 KB)' < "$output_file" 48 | grep -F 'NEW: test/images/flag.png (2000x1263 px @ 84 KB)' < "$output_file" 49 | 50 | rm "$output_file" 51 | } 52 | 53 | it_works_with_small_files() { 54 | output_file=$(run_spaceman \ 55 | "test/images/gooder-flag.png" \ 56 | "test/images/gooder-flag.png" a190ba 100644 \ 57 | "test/images/small-image.png" 000000 100644) 58 | 59 | grep -F 'OLD: test/images/gooder-flag.png (2000x1236 px @ 9 KB)' < "$output_file" 60 | grep -F 'NEW: test/images/small-image.png (36x38 px @ 0 KB)' < "$output_file" 61 | 62 | rm "$output_file" 63 | } 64 | -------------------------------------------------------------------------------- /test/images/flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/holman/spaceman-diff/b81423c93e9fcd9251e54767e45e95731ea975c1/test/images/flag.png -------------------------------------------------------------------------------- /test/images/gooder-flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/holman/spaceman-diff/b81423c93e9fcd9251e54767e45e95731ea975c1/test/images/gooder-flag.png -------------------------------------------------------------------------------- /test/images/small-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/holman/spaceman-diff/b81423c93e9fcd9251e54767e45e95731ea975c1/test/images/small-image.png -------------------------------------------------------------------------------- /test/images/with spaces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/holman/spaceman-diff/b81423c93e9fcd9251e54767e45e95731ea975c1/test/images/with spaces.png -------------------------------------------------------------------------------- /tests: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Run roundup tests for spaceman-diff. 4 | # 5 | 6 | roundup=$(which roundup) 7 | 8 | [ ! -z $roundup ] || { 9 | cat <&2 ; 10 | error: roundup missing 11 | 12 | Check out https://github.com/bmizerany/roundup for instructions on installing roundup. 13 | MESSAGE 14 | 15 | exit 1; 16 | } 17 | 18 | $roundup ./*-test.sh 19 | --------------------------------------------------------------------------------