From 3895dd003ddfe16835b4d774d74ee9070bfbcde9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 14 Oct 2019 19:04:10 +0300 Subject: [PATCH 1/5] pfetch: disk support --- pfetch | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/pfetch b/pfetch index 0307e99..235b8d5 100755 --- a/pfetch +++ b/pfetch @@ -694,6 +694,67 @@ get_memory() { log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6 } +get_disk() { + # Store the version of the 'df' command as the available + # flags, options and implementation differs between operating + # systems and we need to handle these edge-cases. + df_version=$(df --version 2>&1) + + case $df_version in + # The 'df' command is from AIX. + *IMitv*) + set -- -P -g + ;; + + # The 'df' command is from IRIX. + *befhikm*) + set -- -P -k + ;; + + # The 'df' command is from OpenBSD. + *hiklnP*) + set -- -h + ;; + + # The 'df' command is from Haiku and is wildly + # different and provides no workable output, + # end here. + *Tracker*) # Haiku + return + ;; + + # From testing it is saffe to assume that + # any other 'df' version provides these flags. + *) + set -- -P -h + ;; + esac + + # Read the output of 'df' line by line. The first line + # contains header information for the "table" so it is + # skipped. + # + # The next lines are then split to grab the relevant + # information and thankfully the output remains the + # same between all but one 'df' implementation. + # + # TODO: Configure disks to send to 'df'. Do we need to + # do this? I'd love to _not_ do it. + df "$@" / | while read -r name full used _ perc _; do + [ "$header" ] || { header=1; continue; } + + case $df_version in + # The 'df' command is from IRIX. + *befhikm*) + used=$((used/1024/1024))G + full=$((full/1024/1024))G + ;; + esac + + log disk "$name [$used / $full ($perc)]" >&6 + done +} + get_wm() { case $os in # Don't display window manager on macOS. @@ -1302,12 +1363,8 @@ get_ascii() { # output without the use of a pipe ('|'). # This ensures that any variables defined in the while loop # are still accessible in the script. - # - # The 'awk' command below used to be a simple 'sed', however - # some versions of Android shipped with a totally broken 'sed' - # command from 'toybox' and so we're forced to avoid 'sed'. done <<-EOF - $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') + $(printf %s "$ascii" | sed 's/\[3.m//g') EOF # Add a gap between the ascii art and the information. From 0f1d6845dbc836be234b6a205d6b52ad6c5ad0eb Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 14 Oct 2019 19:05:36 +0300 Subject: [PATCH 2/5] pfetch: revert unrelated commit. --- pfetch | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pfetch b/pfetch index 235b8d5..7015283 100755 --- a/pfetch +++ b/pfetch @@ -1363,8 +1363,12 @@ get_ascii() { # output without the use of a pipe ('|'). # This ensures that any variables defined in the while loop # are still accessible in the script. + # + # The 'awk' command below used to be a simple 'sed', however + # some versions of Android shipped with a totally broken 'sed' + # command from 'toybox' and so we're forced to avoid 'sed'. done <<-EOF - $(printf %s "$ascii" | sed 's/\[3.m//g') + $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') EOF # Add a gap between the ascii art and the information. From 0834d53b2a745c40f744b95db9b596eba12c08c3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 14 Oct 2019 19:06:31 +0300 Subject: [PATCH 3/5] pfetch: revert unrelated commit. --- pfetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pfetch b/pfetch index 7015283..ebc0730 100755 --- a/pfetch +++ b/pfetch @@ -1368,7 +1368,7 @@ get_ascii() { # some versions of Android shipped with a totally broken 'sed' # command from 'toybox' and so we're forced to avoid 'sed'. done <<-EOF - $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') + $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') EOF # Add a gap between the ascii art and the information. From 219d8f21177f7f31fe9c1f39c7c825bb4559113e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 14 Oct 2019 19:10:42 +0300 Subject: [PATCH 4/5] pfetch: revert unrelated commit. --- pfetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pfetch b/pfetch index ebc0730..7472070 100755 --- a/pfetch +++ b/pfetch @@ -1368,7 +1368,7 @@ get_ascii() { # some versions of Android shipped with a totally broken 'sed' # command from 'toybox' and so we're forced to avoid 'sed'. done <<-EOF - $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') + $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') EOF # Add a gap between the ascii art and the information. From af166966b9955d9ff1b7545ed7557d9c22a1ccde Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 14 Oct 2019 19:11:26 +0300 Subject: [PATCH 5/5] pfetch: revert unrelated commit. --- pfetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pfetch b/pfetch index 7472070..34e5836 100755 --- a/pfetch +++ b/pfetch @@ -1368,7 +1368,7 @@ get_ascii() { # some versions of Android shipped with a totally broken 'sed' # command from 'toybox' and so we're forced to avoid 'sed'. done <<-EOF - $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') + $(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}') EOF # Add a gap between the ascii art and the information.