From 82a11c00fe5d443fa0604cf21cc098d932176f5c Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 04 May 2018 12:39:01 -0400 Subject: bin/chdt: Read desktop geometry settings from rc file --- (limited to 'bin/chdt') diff --git a/bin/chdt b/bin/chdt index a6e1e5d..3a29ae5 100755 --- a/bin/chdt +++ b/bin/chdt @@ -2,9 +2,10 @@ set -eu -ROWS=2 -COLS=6 -ORIENTATION='horizontal' +# Default values, overridden in ~/.chdtrc +rows=2 +cols=6 +orientation='horizontal' debug=0 @@ -53,22 +54,22 @@ inc_desktop() local dx=${2} local dy=${3} - case "${ORIENTATION}" in + case "${orientation}" in [Hh]*) - x=$((${dt} % ${COLS})) - y=$((${dt} / ${COLS})) + x=$((${dt} % ${cols})) + y=$((${dt} / ${cols})) dbg 'Old coordinates: (%d, %d)' ${x} ${y} - x=$(((${x} + ${COLS} + ${dx}) % ${COLS})) - y=$(((${y} + ${ROWS} + ${dy}) % ${ROWS})) + x=$(((${x} + ${cols} + ${dx}) % ${cols})) + y=$(((${y} + ${rows} + ${dy}) % ${rows})) dbg 'New coordinates: (%d, %d)' ${x} ${y} - dt=$((${y} * ${COLS} + ${x})) + dt=$((${y} * ${cols} + ${x})) ;; [Vv]*) - x=$((${dt} / ${ROWS})) - y=$((${dt} % ${ROWS})) - x=$(((${x} + ${dx}) % ${COLS})) - y=$(((${y} + ${dy}) % ${ROWS})) - dt=$((${x} * ${ROWS} + ${y})) + x=$((${dt} / ${rows})) + y=$((${dt} % ${rows})) + x=$(((${x} + ${dx}) % ${cols})) + y=$(((${y} + ${dy}) % ${rows})) + dt=$((${x} * ${rows} + ${y})) ;; esac @@ -162,6 +163,11 @@ main() ;; esac + # POSIX on the dot utility: + # "If no readable file is found, a non-interactive shell shall abort" + # So to survive an ENOENT or other error, we need this eval/cat command. + eval "$(cat ~/.chdtrc 2>/dev/null || :)" + cur_dt=$(get_desktop) || return 1 new_dt=$(inc_desktop ${cur_dt} ${dx} ${dy}) case ${move_win} in -- cgit v0.9.1