diff options
author | P. J. McDermott <pj@pehjota.net> | 2018-04-26 18:58:13 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2018-04-26 18:58:13 (EDT) |
commit | ecdf1aa05271c2b5c33c9fcbb77e39d47f8a669d (patch) | |
tree | ab65741576434a2363ddbe675c3d758eb00edf50 | |
parent | 49f42ae806dfb176081e9ef2fd7953af4374892f (diff) | |
download | fluxbox-ecdf1aa05271c2b5c33c9fcbb77e39d47f8a669d.zip fluxbox-ecdf1aa05271c2b5c33c9fcbb77e39d47f8a669d.tar.gz fluxbox-ecdf1aa05271c2b5c33c9fcbb77e39d47f8a669d.tar.bz2 |
bin/hwmon: Make indentation level configurable
-rwxr-xr-x | bin/hwmon | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -130,12 +130,13 @@ format_power() print_sensor() { - local label="${1}" - local len=${2} - local chip="${3}" - local chips="${4}" - local element="${5}" - shift 5 + local indent=${1} + local label="${2}" + local len=${3} + local chip="${4}" + local chips="${5}" + local element="${6}" + shift 6 local hwmon= local value= local i= @@ -164,7 +165,12 @@ print_sensor() ;; esac - printf ' %s:' "${label}" + i=0 + while [ ${i} -lt ${indent} ]; do + printf ' ' + i=$((${i} + 1)) + done + printf '%s:' "${label}" i=${#label} while [ ${i} -lt ${len} ]; do printf ' ' @@ -184,12 +190,14 @@ usage() '<label>:<chip>/<element>' '<label>:<chip>/<element>' printf '\n' printf 'Options:\n' + printf ' -i <num> Indent label/value lines with <num> spaces\n' printf ' -r Print carriage returns instead of line feeds\n' printf ' -d Enable debugging output\n' } main() { + local indent= local opt= local chips= local max_len= @@ -199,8 +207,16 @@ main() local chip= local element= - while getopts 'rd' opt "${@}"; do + indent=0 + while getopts 'i:rd' opt "${@}"; do case "${opt}" in + 'i') + case "${OPTARG}" in *[!0-9]* | '') + usage 1>&2 + return 1 + esac + indent=${OPTARG} + ;; 'r') cr=1;; 'd') debug=1;; '?') @@ -239,7 +255,7 @@ main() esac chip="${sensor%/*}" element="${sensor##*/}" - print_sensor "${label}" ${len} \ + print_sensor ${indent} "${label}" ${len} \ "${chip}" "${chips}" "${element}" || return 1 done |