From a1a25aa80ade2e88b0a8c0d1ec8996ea62788952 Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 22 Jun 2022 01:01:59 +0000 Subject: [PATCH] x-dpi-facesizes.sh: support an optional paramter --- utils/scripts/x-dpi-facesizes.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/utils/scripts/x-dpi-facesizes.sh b/utils/scripts/x-dpi-facesizes.sh index 0b35687..c684799 100644 --- a/utils/scripts/x-dpi-facesizes.sh +++ b/utils/scripts/x-dpi-facesizes.sh @@ -10,11 +10,22 @@ # Dedication along with this software. If not, see # . +usage() +{ + printf "Usage: %s [targetdpi]\n" "${0##*/}" >&2 + exit 1 +} + +if [ $# -gt 1 ]; then + usage +fi + FACESIZES="10.5 6.0 8.0 9.0 10.5 12.0 18.0" BASEDPI=96 -targetdpi=96 -if command -v xdpyinfo >/dev/null 2>&1; then +if [ -n "$1" ]; then + targetdpi=$1 +elif command -v xdpyinfo >/dev/null 2>&1; then targetdpi=$(xdpyinfo | grep '^ resolution:' | { min= while read -r line; do @@ -29,13 +40,12 @@ if command -v xdpyinfo >/dev/null 2>&1; then fi done - if [ -z "$min" ]; then - echo 96 - else + if [ -n "$min" ]; then echo "$min / 2" | bc -l fi }) fi +: ${targetdpi:=96} for facesize in $FACESIZES; do echo "$BASEDPI * $facesize / $targetdpi"