From b3733f3937fdd9b332ef4e5fdec88af1225b2e57 Mon Sep 17 00:00:00 2001 From: ranomier Date: Tue, 3 Dec 2024 03:37:17 +0100 Subject: [PATCH 1/3] made the script real nice --- main.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/main.sh b/main.sh index 177111f..4d6e7e6 100755 --- a/main.sh +++ b/main.sh @@ -1,17 +1,22 @@ #!/usr/bin/env sh -# takes two optional arguments -# -t path to pango formated text file -# https://usage.imagemagick.org/text/#pango -# this can be overwritten with the text inside a env var named -# IMAGE_TEXT -# -# -p is a path to write the jpg to -# alternativly you can write the path into PICTURE_PATH -set -E -o pipefail -set -x -export LC_ALL='C.UTF8' +set -ex -export SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +help_text() { + printf " +-t path to pango formated text file + how to format: https://usage.imagemagick.org/text/#pango + as an environment variable IMAGE_TEXT not with path but the text itself + if -t is set the environment variable will be ignored + +-p is a path to write the jpg to + as an environment variable PICTURE_PATH + if -p is set the environment variable will be ignored + " + exit 1 +} + +export LC_ALL='C.UTF8' +export SCRIPT_DIR="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" P_PATH="$SCRIPT_DIR/label.jpg" I_TEXT="$(cat "$SCRIPT_DIR"/text.pango 2>/dev/null || echo 'example text')" @@ -23,7 +28,8 @@ while getopts "p:t:" opt do case "$opt" in p) P_PATH="$OPTARG";; - t) I_TEXT="$OPTARG";; + t) I_TEXT=$(cat "$OPTARG");; + *) help_text esac done @@ -33,3 +39,4 @@ magick \ -font 'FiraCode Nerd Font' \ -pointsize 72 pango:"$I_TEXT" \ "$P_PATH" + From 34e11c534395332588dfb42fa0a47fd3977be37b Mon Sep 17 00:00:00 2001 From: ranomier Date: Tue, 3 Dec 2024 03:48:03 +0100 Subject: [PATCH 2/3] declare seperatly --- main.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.sh b/main.sh index 4d6e7e6..da67f38 100755 --- a/main.sh +++ b/main.sh @@ -16,7 +16,8 @@ help_text() { } export LC_ALL='C.UTF8' -export SCRIPT_DIR="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" +SCRIPT_DIR="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" +export SCRIPT_DIR P_PATH="$SCRIPT_DIR/label.jpg" I_TEXT="$(cat "$SCRIPT_DIR"/text.pango 2>/dev/null || echo 'example text')" From 0b3132e355e8b3732e3d6ba98177534cd03d4b9f Mon Sep 17 00:00:00 2001 From: ranomier Date: Tue, 3 Dec 2024 03:48:28 +0100 Subject: [PATCH 3/3] fix indent --- main.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.sh b/main.sh index da67f38..339cc3c 100755 --- a/main.sh +++ b/main.sh @@ -27,11 +27,11 @@ I_TEXT="${IMAGE_TEXT:-$I_TEXT}" while getopts "p:t:" opt do - case "$opt" in - p) P_PATH="$OPTARG";; - t) I_TEXT=$(cat "$OPTARG");; - *) help_text - esac + case "$opt" in + p) P_PATH="$OPTARG";; + t) I_TEXT=$(cat "$OPTARG");; + *) help_text + esac done magick \