mirror of
https://github.com/smxi/inxi.git
synced 2025-01-19 08:57:57 +00:00
gawk code cleanup, got rid of all one line flow controls, got rid of all ; separated statements, made all gawk code line
up with columns it occurs in.
This commit is contained in:
parent
82c3d091a8
commit
84d1fb5ab0
55
inxi
55
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 0.3.26
|
#### version: 0.3.27
|
||||||
#### Date: November 6 2008
|
#### Date: November 6 2008
|
||||||
########################################################################
|
########################################################################
|
||||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||||
|
@ -43,7 +43,6 @@
|
||||||
## a lot more data and verbosity levels going
|
## a lot more data and verbosity levels going
|
||||||
|
|
||||||
### Variable initializations: null values
|
### Variable initializations: null values
|
||||||
|
|
||||||
CMDL_MAX=''
|
CMDL_MAX=''
|
||||||
COLOR_SCHEME=''
|
COLOR_SCHEME=''
|
||||||
COLOR_SCHEME_SET=''
|
COLOR_SCHEME_SET=''
|
||||||
|
@ -302,15 +301,20 @@ remove_erroneous_chars()
|
||||||
{
|
{
|
||||||
## RS is input record separator
|
## RS is input record separator
|
||||||
## gsub is substitute;
|
## gsub is substitute;
|
||||||
gawk 'BEGIN { RS="" } { gsub(/\n$/,"") ## (newline; end of string) with (nothing)
|
gawk 'BEGIN { RS="" } {
|
||||||
|
gsub(/\n$/,"") ## (newline; end of string) with (nothing)
|
||||||
gsub(/\n/," "); ## (newline) with (space)
|
gsub(/\n/," "); ## (newline) with (space)
|
||||||
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
|
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
|
||||||
gsub(/ +/, " ") ## ( +) with (space)
|
gsub(/ +/, " ") ## ( +) with (space)
|
||||||
gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
|
gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
|
||||||
gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
|
gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
|
||||||
printf $0 }' "$1" ## prints (returns) cleaned input
|
printf $0
|
||||||
|
}' "$1" ## prints (returns) cleaned input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## note: this is now running inside each awk sequence directly to avoid exiting awk
|
||||||
|
## looping in bash through arrays, then re-entering awk to clean up, then writing back to array
|
||||||
|
## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
|
||||||
# Enforce boilerplate and buzzword filters
|
# Enforce boilerplate and buzzword filters
|
||||||
# args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
|
# args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
|
||||||
sanitize_characters()
|
sanitize_characters()
|
||||||
|
@ -318,10 +322,13 @@ sanitize_characters()
|
||||||
# Cannot use strong quotes to unquote a string with pipes in it!
|
# Cannot use strong quotes to unquote a string with pipes in it!
|
||||||
# bash will interpret the |'s as usual and try to run a subshell!
|
# bash will interpret the |'s as usual and try to run a subshell!
|
||||||
# Using weak quotes instead, or use '"..."'
|
# Using weak quotes instead, or use '"..."'
|
||||||
echo "$2" | gawk "BEGIN { IGNORECASE=1 } {gsub(/${!1}/,\"\")
|
echo "$2" | gawk "
|
||||||
|
BEGIN { IGNORECASE=1 } {
|
||||||
|
gsub(/${!1}/,\"\")
|
||||||
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
|
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
|
||||||
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
|
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
|
||||||
print }" ## prints (returns) cleaned input
|
print ## prints (returns) cleaned input
|
||||||
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#### -------------------------------------------------------------------
|
#### -------------------------------------------------------------------
|
||||||
|
@ -375,7 +382,10 @@ make_ban_lists()
|
||||||
ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}"
|
ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}"
|
||||||
else
|
else
|
||||||
# Automatically escapes [ ] ( ) . and +
|
# Automatically escapes [ ] ( ) . and +
|
||||||
ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{ gsub(/([\[\]+().])/,"\\\\&"); print }' )"
|
ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{
|
||||||
|
gsub(/([\[\]+().])/,"\\\\&")
|
||||||
|
print
|
||||||
|
}' )"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -654,12 +664,14 @@ get_start_client()
|
||||||
/Version/ {
|
/Version/ {
|
||||||
a=tolower($2)
|
a=tolower($2)
|
||||||
gsub(/[()]|bitchx-/,"",a)
|
gsub(/[()]|bitchx-/,"",a)
|
||||||
print a; exit
|
print a
|
||||||
|
exit
|
||||||
}
|
}
|
||||||
$2 == "version" {
|
$2 == "version" {
|
||||||
a=tolower($3)
|
a=tolower($3)
|
||||||
sub(/bitchx-/,"",a)
|
sub(/bitchx-/,"",a)
|
||||||
print a; exit
|
print a
|
||||||
|
exit
|
||||||
}
|
}
|
||||||
' )"
|
' )"
|
||||||
IRC_CLIENT="BitchX"
|
IRC_CLIENT="BitchX"
|
||||||
|
@ -694,7 +706,11 @@ get_start_client()
|
||||||
IRC_CLIENT="KVIrc"
|
IRC_CLIENT="KVIrc"
|
||||||
;;
|
;;
|
||||||
*kopete*)
|
*kopete*)
|
||||||
IRC_CLIENT_VERSION=" $( kopete -v | gawk '/Kopete:/ { print $2; exit }' )"
|
IRC_CLIENT_VERSION=" $( kopete -v | gawk '
|
||||||
|
/Kopete:/ {
|
||||||
|
print $2
|
||||||
|
exit
|
||||||
|
}' )"
|
||||||
IRC_CLIENT="Kopete"
|
IRC_CLIENT="Kopete"
|
||||||
;;
|
;;
|
||||||
*perl*)
|
*perl*)
|
||||||
|
@ -713,7 +729,11 @@ get_start_client()
|
||||||
# You can imagine how hosed I am if I try to make inxi find out dynamically with which path
|
# You can imagine how hosed I am if I try to make inxi find out dynamically with which path
|
||||||
# KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
|
# KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
|
||||||
# (KSirc sucks anyway ;)
|
# (KSirc sucks anyway ;)
|
||||||
IRC_CLIENT_VERSION=" $( ksirc -v | gawk '/KSirc:/ { print $2; exit }' )"
|
IRC_CLIENT_VERSION=" $( ksirc -v | gawk '
|
||||||
|
/KSirc:/ {
|
||||||
|
print $2
|
||||||
|
exit
|
||||||
|
}' )"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -782,7 +802,7 @@ set_calculated_variables()
|
||||||
get_audio_data()
|
get_audio_data()
|
||||||
{
|
{
|
||||||
local i=''
|
local i=''
|
||||||
|
tt='nvidia'
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
A_AUDIO_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
A_AUDIO_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
||||||
{ IGNORECASE=1 }
|
{ IGNORECASE=1 }
|
||||||
|
@ -944,7 +964,8 @@ get_distro_data()
|
||||||
# Debian pure should fall through here
|
# Debian pure should fall through here
|
||||||
distro_file="issue"
|
distro_file="issue"
|
||||||
distro=$( gawk '
|
distro=$( gawk '
|
||||||
BEGIN { RS="" } {
|
BEGIN
|
||||||
|
{ RS="" } {
|
||||||
gsub(/\\[a-z]/, "")
|
gsub(/\\[a-z]/, "")
|
||||||
gsub(/,/, " ")
|
gsub(/,/, " ")
|
||||||
gsub(/^ +| +$/, "")
|
gsub(/^ +| +$/, "")
|
||||||
|
@ -976,7 +997,7 @@ get_graphics_card_data()
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '
|
||||||
{ IGNORECASE=1 }
|
{ IGNORECASE=1 }
|
||||||
/VGA compatible controller/ {
|
/vga compatible controller/ {
|
||||||
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
|
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF)
|
||||||
gsub(/,/, " ", $NF)
|
gsub(/,/, " ", $NF)
|
||||||
gsub(/^ +| +$/, "", $NF)
|
gsub(/^ +| +$/, "", $NF)
|
||||||
|
@ -1015,7 +1036,6 @@ get_graphics_glx_data()
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN { IGNORECASE=1 }
|
BEGIN { IGNORECASE=1 }
|
||||||
|
|
||||||
/opengl renderer/ {
|
/opengl renderer/ {
|
||||||
if ($2 ~ /mesa/) {
|
if ($2 ~ /mesa/) {
|
||||||
# Allow r300 et al, but not the rest
|
# Allow r300 et al, but not the rest
|
||||||
|
@ -1229,7 +1249,10 @@ get_hard_drive_data()
|
||||||
|
|
||||||
get_lspci_data()
|
get_lspci_data()
|
||||||
{
|
{
|
||||||
echo "$( lspci -v | awk '{ gsub(/\(prog-if[^)]*\)/,""); print }' )"
|
echo "$( lspci -v | awk '{
|
||||||
|
gsub(/\(prog-if[^)]*\)/,"")
|
||||||
|
print
|
||||||
|
}' )"
|
||||||
}
|
}
|
||||||
|
|
||||||
## return memory used/installed
|
## return memory used/installed
|
||||||
|
|
Loading…
Reference in a new issue