mirror of
https://github.com/smxi/inxi.git
synced 2025-01-19 00:47:47 +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
159
inxi
159
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) with (space)
|
gsub(/\n$/,"") ## (newline; end of string) with (nothing)
|
||||||
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
|
gsub(/\n/," "); ## (newline) with (space)
|
||||||
gsub(/ +/, " ") ## ( +) with (space)
|
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
|
||||||
gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
|
gsub(/ +/, " ") ## ( +) with (space)
|
||||||
gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
|
gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
|
||||||
printf $0 }' "$1" ## prints (returns) cleaned input
|
gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
|
||||||
|
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 "
|
||||||
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
|
BEGIN { IGNORECASE=1 } {
|
||||||
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
|
gsub(/${!1}/,\"\")
|
||||||
print }" ## prints (returns) cleaned input
|
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
|
||||||
|
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -603,17 +613,17 @@ get_start_client()
|
||||||
KONVI=1
|
KONVI=1
|
||||||
fi
|
fi
|
||||||
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
|
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
|
||||||
/Konversation:/ {
|
/Konversation:/ {
|
||||||
for ( i=2; i<=NF; i++ ) {
|
for ( i=2; i<=NF; i++ ) {
|
||||||
if (i == NF) {
|
if (i == NF) {
|
||||||
print $i
|
print $i
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf $i" "
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exit
|
else {
|
||||||
}' )"
|
printf $i" "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit
|
||||||
|
}' )"
|
||||||
T=($IRC_CLIENT_VERSION)
|
T=($IRC_CLIENT_VERSION)
|
||||||
if [[ ${T[0]} == *+* ]];then
|
if [[ ${T[0]} == *+* ]];then
|
||||||
# < Sho_> locsmif: The version numbers of SVN versions look like this:
|
# < Sho_> locsmif: The version numbers of SVN versions look like this:
|
||||||
|
@ -627,12 +637,12 @@ get_start_client()
|
||||||
fi
|
fi
|
||||||
# Remove any dots except the first, and make sure there are no trailing zeroes,
|
# Remove any dots except the first, and make sure there are no trailing zeroes,
|
||||||
T2=$( echo "$T2" | gawk '
|
T2=$( echo "$T2" | gawk '
|
||||||
{
|
{
|
||||||
sub(/\./, " ")
|
sub(/\./, " ")
|
||||||
gsub(/\./, "")
|
gsub(/\./, "")
|
||||||
sub(/ /, ".")
|
sub(/ /, ".")
|
||||||
printf("%g\n", $0)
|
printf("%g\n", $0)
|
||||||
}' )
|
}' )
|
||||||
# Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
|
# Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
|
||||||
# becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
|
# becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
|
||||||
# than 1 and change the DCOP parameter/object accordingly.
|
# than 1 and change the DCOP parameter/object accordingly.
|
||||||
|
@ -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,17 +802,17 @@ 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 }
|
||||||
/multimedia audio controller|audio device/ {
|
/multimedia audio controller|audio device/ {
|
||||||
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
|
gsub(/'"$BAN_LIST_NORMAL"'/, "", $NF )
|
||||||
gsub(/,/," ",$NF)
|
gsub(/,/," ",$NF)
|
||||||
gsub(/^ +| +$/,"",$NF)
|
gsub(/^ +| +$/,"",$NF)
|
||||||
gsub(/ [ \t]+/," ",$NF)
|
gsub(/ [ \t]+/," ",$NF)
|
||||||
print $NF
|
print $NF
|
||||||
}' ) )
|
}' ) )
|
||||||
IFS="$ORIGINAL_IFS"
|
IFS="$ORIGINAL_IFS"
|
||||||
|
|
||||||
# handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
|
# handle cases where card detection fails, like in PS3, where lspci gives no output, or headless boxes..
|
||||||
|
@ -944,13 +964,14 @@ 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
|
||||||
gsub(/\\[a-z]/, "")
|
{ RS="" } {
|
||||||
gsub(/,/, " ")
|
gsub(/\\[a-z]/, "")
|
||||||
gsub(/^ +| +$/, "")
|
gsub(/,/, " ")
|
||||||
gsub(/ [ \t]+/, " ")
|
gsub(/^ +| +$/, "")
|
||||||
print
|
gsub(/ [ \t]+/, " ")
|
||||||
}' "/etc/${distro_file}" )
|
print
|
||||||
|
}' "/etc/${distro_file}" )
|
||||||
fi
|
fi
|
||||||
if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then
|
if [[ ${#distro} -gt 80 && $B_HANDLE_CORRUPT_DATA != 'true' ]];then
|
||||||
distro="${RED}/etc/${distro_file} corrupted, use -C to override${NORMAL}"
|
distro="${RED}/etc/${distro_file} corrupted, use -C to override${NORMAL}"
|
||||||
|
@ -975,15 +996,15 @@ 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)
|
||||||
gsub(/ [ \t]+/, " ", $NF)
|
gsub(/ [ \t]+/, " ", $NF)
|
||||||
print $NF
|
print $NF
|
||||||
}'
|
}'
|
||||||
) )
|
) )
|
||||||
IFS="$ORIGINAL_IFS"
|
IFS="$ORIGINAL_IFS"
|
||||||
# for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
|
# for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ ))
|
||||||
# do
|
# do
|
||||||
|
@ -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
|
||||||
|
@ -1102,13 +1122,13 @@ get_graphics_x_data()
|
||||||
x_version=$( xdpyinfo | awk '/version:/ { print $NF }' )
|
x_version=$( xdpyinfo | awk '/version:/ { print $NF }' )
|
||||||
if [[ -z $x_version ]];then
|
if [[ -z $x_version ]];then
|
||||||
x_version=$(xdpyinfo | gawk -F': +' '
|
x_version=$(xdpyinfo | gawk -F': +' '
|
||||||
BEGIN { IGNORECASE=1 }
|
BEGIN { IGNORECASE=1 }
|
||||||
/vendor release number/ {
|
/vendor release number/ {
|
||||||
gsub(/0+$/, "", $2)
|
gsub(/0+$/, "", $2)
|
||||||
gsub(/0+/, ".", $2)
|
gsub(/0+/, ".", $2)
|
||||||
print $2
|
print $2
|
||||||
}
|
}
|
||||||
')
|
')
|
||||||
fi
|
fi
|
||||||
A_X_DATA[0]="$x_vendor"
|
A_X_DATA[0]="$x_vendor"
|
||||||
A_X_DATA[1]="$x_version"
|
A_X_DATA[1]="$x_version"
|
||||||
|
@ -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