aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2019-09-27 10:08:07 +0300
committerDylan Araps <dylan.araps@gmail.com>2019-09-27 10:08:07 +0300
commit4459f8188f33a8c817e05604d6bc7ef4017ac4c1 (patch)
tree63bb6cb597d0292e0641c16c5abc21bb354959ee
parent7ec3239d0cee80274b5f2655c20a69c5fabb8022 (diff)
downloadpfetch-4459f8188f33a8c817e05604d6bc7ef4017ac4c1.tar.gz
host: strip OEM information
-rwxr-xr-xpfetch37
1 files changed, 37 insertions, 0 deletions
diff --git a/pfetch b/pfetch
index 04a8bcf..fd4ee8b 100755
--- a/pfetch
+++ b/pfetch
@@ -277,6 +277,43 @@ get_host() {
;;
esac
+ # Turn the host string into an argument list so we can iterate
+ # over it and remove OEM strings and other information which
+ # shouldn't be displayed.
+ #
+ # Disable the shellcheck warning for word-splitting
+ # as it's safe and intended ('set -f' disables globbing).
+ # shellcheck disable=2046,2086
+ {
+ set -f
+ set +f -- $host
+ host=
+ }
+
+ # Iterate over the host string word by word as a means of stripping
+ # unwanted and OEM information from the string as a whole.
+ #
+ # This could have been implemented using a long 'sed' command with
+ # a list of word replacements, however I want to show that something
+ # like this is possible in pure sh.
+ #
+ # This string reconstruction is needed as some OEMs either leave the
+ # identification information as "To be filled by OEM", "Default",
+ # "undefined" etc and we shouldn't print this to the screen.
+ for word; do
+ # This works by reconstructing the string by excluding words
+ # found in the "blacklist" below. Only non-matches are appended
+ # to the final host string.
+ case $word in
+ To | [Bb]e | [Ff]illed | by | O.E.M. | OEM |\
+ Not | Applicable | Specified | System | Product | Name |\
+ Version | Undefined | Default | string | INVALID | � )
+ continue
+ esac
+
+ host="$host$word "
+ done
+
# '$arch' is the cached output from 'uname -m'.
log host "${host:-$arch}" >&6
}