aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2023-04-25 10:40:06 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2023-04-25 10:40:06 +0200
commit6ec0f9b2a2475d0bf39fc85b5dc38597d0df7542 (patch)
treeb75196929badbe55992dc886f53a96a16e9afa4d
parent7212da7e707a9e17b7182281e4d912a88f7f9cea (diff)
downloadscripts-6ec0f9b2a2475d0bf39fc85b5dc38597d0df7542.tar.gz
scripts-6ec0f9b2a2475d0bf39fc85b5dc38597d0df7542.zip
Added folder for scripts for games and script to join images in 3x3 grid.
-rwxr-xr-xgames/mtg/cardToHtml.sh41
-rwxr-xr-xgames/mtg/deckLister.sh62
-rwxr-xr-xgames/mtg/getScryfallJSON.sh37
-rwxr-xr-ximages/matrix9.sh39
-rwxr-xr-xxinit.sh2
5 files changed, 180 insertions, 1 deletions
diff --git a/games/mtg/cardToHtml.sh b/games/mtg/cardToHtml.sh
new file mode 100755
index 0000000..c7a93dc
--- /dev/null
+++ b/games/mtg/cardToHtml.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# cardToHtml.sh: Generates an image HTML tag of an MTG card, with the name of
+# the card as alternate text and the image being a link to its Scryfall page.
+#
+# Usage: cardToHtml.sh CARDNAME
+#
+# Exotic dependencies: jq
+
+usageMessage="Usage: ${0} CARDNAME"
+
+error() {
+ printf '%s error: %s\n' "$0" "$*" >&2
+}
+
+errorAndUsage() {
+ printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
+}
+
+# Process options
+while getopts ':' opt; do
+ case $opt in
+
+ '?' )
+ printf '%s\n' "$usageMessage" >&2
+ exit 1
+
+ esac
+done
+shift $((OPTIND - 1))
+
+json="$(getScryfallJSON.sh "$@")"
+[ -z "$json" ] && exit 1
+cardName="$(echo "$json" | jq -r '.name')"
+imageUrl="$(echo "$json" | jq -r '.image_uris.large' | sed 's/?.*$//')"
+scryfallUrl="$(echo "$json" | jq -r '.scryfall_uri' | sed 's/?.*$//')"
+
+printf '<a href="%s">
+ <img src="%s"
+ alt="%s">
+</a>\n' "$scryfallUrl" "$imageUrl" "$cardName"
diff --git a/games/mtg/deckLister.sh b/games/mtg/deckLister.sh
new file mode 100755
index 0000000..606ca73
--- /dev/null
+++ b/games/mtg/deckLister.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# deckLister.sh: Interactively reads card names in any language, searches for
+# them and writes them in English line by line.
+#
+# Usage: deckLister.sh [-f FILE]
+
+scriptName="${0##*/}"
+
+usageMessage="Usage: ${scriptName} [-f FILE]"
+
+error() {
+ printf '%s error: %s\n' "$scriptName" "$*" >&2
+}
+
+errorAndUsage() {
+ printf '%s error: %s\n%s\n' "$scriptName" "$*" "$usageMessage" >&2
+}
+
+file=''
+welcomeMessage="${scriptName}: Input non-ambiguous card names in any language."
+prompt='> '
+
+# Process options
+while getopts ':f:' opt; do
+ case $opt in
+
+ 'f' )
+ file="$OPTARG"
+ ;;
+
+ '?' )
+ printf '%s\n' "$usageMessage" >&2
+ exit 1
+
+ esac
+done
+shift $((OPTIND - 1))
+
+[ -n "$1" ] && errorAndUsage 'Too many arguments.' && exit 1
+
+log() {
+ if [ -n "$file" ]; then
+ printf '%s\n' "$@" >> "$file"
+ else
+ printf '%s\n' "$@"
+ fi
+}
+
+nameToEnglish() {
+ json="$(getScryfallJSON.sh "$@")" || return 1
+ echo "$json" | jq -r .name
+}
+
+echo "$welcomeMessage" >&2
+
+while true; do
+ printf '%s' "$prompt" >&2
+ read -r cardname
+ englishName="$(nameToEnglish "$cardname")"
+ [ -n "$englishName" ] && log "$englishName"
+done
diff --git a/games/mtg/getScryfallJSON.sh b/games/mtg/getScryfallJSON.sh
new file mode 100755
index 0000000..2cc354a
--- /dev/null
+++ b/games/mtg/getScryfallJSON.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# getScryfallJSON.sh: Gets the JSON of a fuzzy Scryfall search.
+#
+# Usage: getScryfallJSON.sh CARDNAME
+
+usageMessage="Usage: ${0} FILE..."
+
+error() {
+ printf '%s error: %s\n' "$0" "$*" >&2
+}
+
+errorAndUsage() {
+ printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
+}
+
+# Process options
+while getopts ':' opt; do
+ case $opt in
+
+ '?' )
+ printf '%s\n' "$usageMessage" >&2
+ exit 1
+
+ esac
+done
+shift $((OPTIND - 1))
+
+url="$(echo "https://api.scryfall.com/cards/named?fuzzy=${*}" | sed 's/ /+/g')"
+json="$(curl "$url" 2>/dev/null)"
+
+if echo "$json" | jq -r .object | grep -q 'error'; then
+ echo "Error: $(echo "$json" | jq)" >&2
+ exit 1
+fi
+
+echo "$json"
diff --git a/images/matrix9.sh b/images/matrix9.sh
new file mode 100755
index 0000000..de37760
--- /dev/null
+++ b/images/matrix9.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# matrixh9.sh: Combine 9 750x1050 images in a grid of 3x3
+#
+# Usage: matrix9.sh FILE...
+
+usageMessage="Usage: ${0} FILE..."
+
+error() {
+ printf '%s error: %s\n' "$0" "$*" >&2
+}
+
+errorAndUsage() {
+ printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
+}
+
+convert \
+ "$1" -extent 2250x1045 \
+ "$2" -gravity center -composite \
+ "$3" -gravity east -composite \
+ "/tmp/row01.jpg"
+
+convert \
+ "$4" -extent 2250x1045 \
+ "$5" -gravity center -composite \
+ "$6" -gravity east -composite \
+ "/tmp/row02.jpg"
+
+convert \
+ "$7" -extent 2250x1045 \
+ "$8" -gravity center -composite \
+ "$9" -gravity east -composite \
+ "/tmp/row03.jpg"
+
+convert \
+ "/tmp/row01.jpg" -extent 2250x3135 \
+ "/tmp/row02.jpg" -gravity center -composite \
+ "/tmp/row03.jpg" -gravity south -composite \
+ "page$(date +%H%M%S).jpg"
diff --git a/xinit.sh b/xinit.sh
index 2fea079..718b53a 100755
--- a/xinit.sh
+++ b/xinit.sh
@@ -11,7 +11,7 @@ initialLayout.sh
setInitialWP.sh
pgrep -x sxhkd || sxhkd >~/logs/sxhkd.log &
-# Swap Escape and Caps except Kyria keyboard is connected
+# Swap Escape and Caps except when Kyria keyboard is connected
if lsusb | grep -Fq 'Kyria'; then
setxkbmap -layout es
else