pfetch: portability with minix

This commit is contained in:
Dylan Araps 2019-09-28 14:49:34 +03:00
parent a43a697551
commit c6f46d5428

24
pfetch
View File

@ -1046,7 +1046,11 @@ get_ascii() {
# the ascii art so they don't affect the width variable. # the ascii art so they don't affect the width variable.
while read -r line; do while read -r line; do
ascii_height=$((ascii_height + 1)) 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 # Using '<<-EOF' is the only way to loop over a command's
# output without the use of a pipe ('|'). # output without the use of a pipe ('|').
@ -1117,8 +1121,12 @@ main() {
# "info names" for output alignment. The option names and subtitles # "info names" for output alignment. The option names and subtitles
# match 1:1 so this is thankfully simple. # match 1:1 so this is thankfully simple.
for info; do for info; do
command -v "get_$info" >/dev/null && command -v "get_$info" >/dev/null || continue
info_length=$((${#info} > info_length ? ${#info} : info_length))
# This was a ternary operation but they aren't supported in
# MINIX's shell.
[ "${#info}" -gt "${info_length:-0}" ] &&
info_length=${#info}
done done
# Add an additional space of length to act as a gap. # 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 # Position the cursor below both the ascii art and information lines
# according to the height of both. If the information exceeds the ascii # 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. # art in height, don't touch the cursor (0/unset), else move it down
cursor_pos=$((info_height > ascii_height ? 0 : ascii_height - info_height)) # 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 # Print '$cursor_pos' amount of newlines to correctly position the
# cursor. This used to be a 'printf $(seq X X)' however 'seq' is only # cursor. This used to be a 'printf $(seq X X)' however 'seq' is only
# typically available (by default) on GNU based systems! # 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' printf '\n'
i=$((i + 1)) i=$((i + 1))
done >&6 done >&6