Skip to content

Instantly share code, notes, and snippets.

@jpf
Last active October 23, 2021 19:41
Show Gist options
  • Save jpf/1f35d59b4e6c35a0d71703620d4c5eac to your computer and use it in GitHub Desktop.
Save jpf/1f35d59b4e6c35a0d71703620d4c5eac to your computer and use it in GitHub Desktop.
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p curl -p xmlstarlet -p imagemagick -p jp2a -p lolcat
#
# showoff.sh:
# Demonstrate the capabilities of Nix by writing a gratuitously complex shell
# script that combines 5 different command line utilities together.
#
# Do the following to run this demo:
# If you don't have Nix yet, install it with this command:
# $ curl https://nixos.org/nix/install | sh
# Make this file executable, so that you can run it via nix-shell:
# $ chmod a+x showoff.sh
# Run this demo!
# $ ./showoff.sh
# Fetch a random image from thecatapi.com using curl(1)
random_image=$(curl -s 'http://thecatapi.com/api/images/get?results_per_page=2&format=xml' | \
# Select the first URL from the results using xmlstarlet(1)
xmlstarlet sel -t -v '(/response/data/images/image/url)[1]')
# Fetch that image using curl(1)
curl -s $random_image | \
# Use Imagmagick's convert(1) utility to make sure the format is JPEG
convert - jpg:- | \
# Use jp2a(1) to turn the image into ASCII art
jp2a - | \
# Make the ASCII art colorful using lolcat from https://github.com/busyloop/lolcat
lolcat 2> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment