Last active
June 22, 2024 02:29
-
-
Save lucaspar/b1ea2785ef678063c12c08bbaae0ee68 to your computer and use it in GitHub Desktop.
Inspirational images paired with questionable advice on the command line. Powered by https://inspirobot.me/
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
# Returns success (0) if the argument exists as a program, alias, or a function. | |
function exists() { | |
# if no argument, show usage and return false | |
if [ -z "${1}" ]; then | |
echo "Usage: exists <program>" | |
return 1 | |
fi | |
command -v "${1}" >/dev/null 2>&1 | |
} | |
# Inspirational images paired with questionable advice on the command line. | |
function inspirobot() { | |
reponse_url=$(curl -s 'https://inspirobot.me/api?generate=true') | |
temp_file=$(mktemp /tmp/inspirobot.XXXXXX.jpg) | |
trap 'rm -f ${temp_file}' EXIT | |
wget -qO "${temp_file}" "${reponse_url}" | |
if exists kitten; then | |
kitten icat "${temp_file}" | |
elif exists feh; then | |
feh "${temp_file}" | |
elif exists sxiv; then | |
sxiv "${temp_file}" | |
elif exists ueberzug; then | |
ueberzug "${temp_file}" | |
elif exists xdg-open; then | |
xdg-open "${temp_file}" | |
elif exists open; then | |
open "${temp_file}" | |
else | |
echo "No image viewer found. Install one of: kitten, feh, sxiv, ueberzug" | |
fi | |
} | |
inspirobot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment