diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2019-09-28 14:49:34 +0300 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2019-09-28 14:49:34 +0300 |
| commit | c6f46d54286db56e08d1d2b6adef2733d354cf5d (patch) | |
| tree | 7e9cfc420dd71eff8739b69e9bd85e83384ee009 | |
| parent | a43a697551ee11c1a1655b9d070b01df73f6d493 (diff) | |
| download | pfetch-c6f46d54286db56e08d1d2b6adef2733d354cf5d.tar.gz | |
pfetch: portability with minix
| -rwxr-xr-x | pfetch | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -1046,7 +1046,11 @@ get_ascii() { # the ascii art so they don't affect the width variable. while read -r line; do ascii_height=$((ascii_height + 1)) - ascii_width=$((${#line} > ascii_width ? ${#line} : ascii_width)) + + # This was a ternary operation but they aren't supported in + # MINIX's shell. + [ "${#line}" -gt "${ascii_width:-0}" ] && + ascii_width=${#line} # Using '<<-EOF' is the only way to loop over a command's # output without the use of a pipe ('|'). @@ -1117,8 +1121,12 @@ main() { # "info names" for output alignment. The option names and subtitles # match 1:1 so this is thankfully simple. for info; do - command -v "get_$info" >/dev/null && - info_length=$((${#info} > info_length ? ${#info} : info_length)) + command -v "get_$info" >/dev/null || continue + + # This was a ternary operation but they aren't supported in + # MINIX's shell. + [ "${#info}" -gt "${info_length:-0}" ] && + info_length=${#info} done # Add an additional space of length to act as a gap. @@ -1130,13 +1138,17 @@ main() { # Position the cursor below both the ascii art and information lines # according to the height of both. If the information exceeds the ascii - # art in height, don't touch the cursor, else move it down N lines. - cursor_pos=$((info_height > ascii_height ? 0 : ascii_height - info_height)) + # art in height, don't touch the cursor (0/unset), else move it down + # N lines. + # + # This was a ternary operation but they aren't supported in MINIX's shell. + [ "$info_height" -lt "$ascii_height" ] && + cursor_pos=$((ascii_height - info_height)) # Print '$cursor_pos' amount of newlines to correctly position the # cursor. This used to be a 'printf $(seq X X)' however 'seq' is only # typically available (by default) on GNU based systems! - while [ "${i:-0}" -le "$cursor_pos" ]; do + while [ "${i:-0}" -le "${cursor_pos:-0}" ]; do printf '\n' i=$((i + 1)) done >&6 |
