Last active
January 10, 2020 16:18
-
-
Save FiXato/55ebbcbc413e9e721460430b13ff663c to your computer and use it in GitHub Desktop.
Wrapper scripts to open each passed URL as an image in various environments (such as Termux on Android, and IrfanView on Cygwin for Windows), meant to be used with the `toot` CLI Mastodon client.
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/env bash | |
PATH_TO_IRFANVIEW="${HOME}/iview454_setup/i_view32.exe" | |
tmpfilelist="$(mktemp "${TMP}/toot_media_viewer.XXXXXX.filelist.txt")" | |
tmpfilelist_win="$(mktemp "${TMP}/toot_media_viewer.XXXXXX.win.filelist.txt")" | |
# Loop through all arguments passed to the script, assuming they are all URLs | |
for url in "$@" | |
do | |
basename="$(basename "$url")" | |
# Get the extension from the URL's basename. Default to 'png' if basename has no period | |
extension="$([[ $basename == *.* ]] && printf '%s' "${basename##*.}" || printf 'png')" | |
# Get a random temp filename. | |
tmpfile="$(mktemp "${TMP}/toot_media_viewer.XXXXXX.${extension}")" | |
# Retrieve the current URL passed via the arguments and store in tmpfile. | |
# Also store the Windows-style path in a newline separated textfile | |
# As well as store the cygwin path in another newline separated textfile for tempfile cleanup | |
curl --silent "$url" > "$tmpfile" && echo "$(cygpath -w "$tmpfile")" >> "$tmpfilelist_win" && echo "$tmpfile" >> "$tmpfilelist" | |
done | |
# Launch IrfanView with a filelist containing Windows paths to the image tempfiles and wait for IrfanView to be closed before continuing with deleting all the tempfiles. | |
cygstart -w -o "$PATH_TO_IRFANVIEW" /filelist="$(cygpath -w "$tmpfilelist_win")" && $(while IFS= read -r file ; do rm -- "$file" ; done < "$tmpfilelist") | |
# Delete both filelists with paths to the tempfiles. | |
rm "$tmpfilelist" | |
rm "$tmpfilelist_win" |
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
#!/bin/sh | |
for var in "$@" | |
do | |
termux-open --content-type image "$var" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment