mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
code refactoring
This commit is contained in:
parent
fa66c967b5
commit
ef7ac17e39
90
inxi
90
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 0.1.3
|
#### version: 0.1.4
|
||||||
#### Date: October 27 2008
|
#### Date: October 27 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
|
||||||
|
@ -118,21 +118,21 @@ fi
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
# inxi speaks through here. When run by Konversation, use DCOP
|
# inxi speaks through here. When run by Konversation, use DCOP
|
||||||
say()
|
print_screen_output()
|
||||||
{
|
{
|
||||||
if (( DEBUG > 5 ))
|
if (( DEBUG > 5 ))
|
||||||
then
|
then
|
||||||
if ((KONVI))
|
if ((KONVI))
|
||||||
then
|
then
|
||||||
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
|
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
|
||||||
else
|
else
|
||||||
echo "konvi='$konvi' saying : '$@'"
|
echo "konvi='$konvi' saying : '$@'"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#((KONVI)) && dcop $DCPORT Konversation say $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
|
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
|
||||||
if (( KONVI ))
|
if (( KONVI ))
|
||||||
then
|
then
|
||||||
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$1"
|
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
|
||||||
else
|
else
|
||||||
echo -ne "$1\n"
|
echo -ne "$1\n"
|
||||||
fi
|
fi
|
||||||
|
@ -143,29 +143,29 @@ error()
|
||||||
{
|
{
|
||||||
case $1 in
|
case $1 in
|
||||||
2)
|
2)
|
||||||
say "$SCRIPT_NAME: large flood danger, debug buffer full!"
|
print_screen_output "$SCRIPT_NAME: large flood danger, debug buffer full!"
|
||||||
;;
|
;;
|
||||||
3)
|
3)
|
||||||
say "$SCRIPT_NAME: error in colorscheme, or unknown parameter: $2"
|
print_screen_output "$SCRIPT_NAME: error in colorscheme, or unknown parameter: $2"
|
||||||
;;
|
;;
|
||||||
4)
|
4)
|
||||||
say "$SCRIPT_NAME: unknown verbosity level $2"
|
print_screen_output "$SCRIPT_NAME: unknown verbosity level $2"
|
||||||
;;
|
;;
|
||||||
5)
|
5)
|
||||||
say "$SCRIPT_NAME: dependency not met: $2 not found in path"
|
print_screen_output "$SCRIPT_NAME: dependency not met: $2 not found in path"
|
||||||
;;
|
;;
|
||||||
6)
|
6)
|
||||||
say "$SCRIPT_NAME: /proc not found! Quitting..."
|
print_screen_output "$SCRIPT_NAME: /proc not found! Quitting..."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
say "$SCRIPT_NAME: error unknown: $@"
|
print_screen_output "$SCRIPT_NAME: error unknown: $@"
|
||||||
set -- 99
|
set -- 99
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg()
|
debug_script()
|
||||||
{
|
{
|
||||||
if (( ALLUP ))
|
if (( ALLUP ))
|
||||||
then
|
then
|
||||||
|
@ -177,11 +177,11 @@ dbg()
|
||||||
then
|
then
|
||||||
for (( DBI=0; DBI < ${#DBGBUF[@]}; DBI++ ))
|
for (( DBI=0; DBI < ${#DBGBUF[@]}; DBI++ ))
|
||||||
do
|
do
|
||||||
say "${DBGBUF[DBI]}"
|
print_screen_output "${DBGBUF[DBI]}"
|
||||||
done
|
done
|
||||||
DBI=0
|
DBI=0
|
||||||
fi
|
fi
|
||||||
say "$@"
|
print_screen_output "$@"
|
||||||
else
|
else
|
||||||
if ((!DEBUG_FLOOD && DBI>10))
|
if ((!DEBUG_FLOOD && DBI>10))
|
||||||
then
|
then
|
||||||
|
@ -208,7 +208,7 @@ checkdepend()
|
||||||
then
|
then
|
||||||
for I in xrandr xdpyinfo glxinfo
|
for I in xrandr xdpyinfo glxinfo
|
||||||
do
|
do
|
||||||
type -p $I >/dev/null || { dbg "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
|
type -p $I >/dev/null || { debug_script "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -273,15 +273,15 @@ getcmdline()
|
||||||
then
|
then
|
||||||
{ echo 0; return; }
|
{ echo 0; return; }
|
||||||
fi
|
fi
|
||||||
##say "Marker"
|
##print_screen_output "Marker"
|
||||||
##say "\$1='$1' -=- $(< /proc/$1/cmdline)"
|
##print_screen_output "\$1='$1' -=- $(< /proc/$1/cmdline)"
|
||||||
local I=0
|
local I=0
|
||||||
unset CMDL
|
unset CMDL
|
||||||
while read -d $'\0' L && [[ $I -lt 32 ]]
|
while read -d $'\0' L && [[ $I -lt 32 ]]
|
||||||
do
|
do
|
||||||
CMDL[I++]="$L"
|
CMDL[I++]="$L"
|
||||||
done </proc/$1/cmdline
|
done </proc/$1/cmdline
|
||||||
##say "\$I='$I'"
|
##print_screen_output "\$I='$I'"
|
||||||
if ! ((I))
|
if ! ((I))
|
||||||
then
|
then
|
||||||
CMDL[0]=$(< /proc/$1/cmdline)
|
CMDL[0]=$(< /proc/$1/cmdline)
|
||||||
|
@ -442,21 +442,21 @@ get_parameters()
|
||||||
echo "$VBL" | grep -q '^[1-3]$' || error 4 "$VBL"
|
echo "$VBL" | grep -q '^[1-3]$' || error 4 "$VBL"
|
||||||
;;
|
;;
|
||||||
-U)
|
-U)
|
||||||
say "Updating $SCRIPT_NAME now..."
|
print_screen_output "Updating $SCRIPT_NAME now..."
|
||||||
wget -O $SCRIPT_PATH/$SCRIPT_NAME http://techpatterns.com/downloads/distro/$SCRIPT_NAME
|
wget -O $SCRIPT_PATH/$SCRIPT_NAME http://techpatterns.com/downloads/distro/$SCRIPT_NAME
|
||||||
say "To run the new version, just start $SCRIPT_NAME again."
|
print_screen_output "To run the new version, just start $SCRIPT_NAME again."
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--version)
|
--version)
|
||||||
say "InfoBash, the universal, portable, system info script for irc."
|
print_screen_output "InfoBash, the universal, portable, system info script for irc."
|
||||||
say "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
|
print_screen_output "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
|
||||||
say "Gaim/Pidgin, Weechat, KVIrc and Kopete."
|
print_screen_output "Gaim/Pidgin, Weechat, KVIrc and Kopete."
|
||||||
say "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif <infobash@rebelhomicide.demon.nl>"
|
print_screen_output "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif <infobash@rebelhomicide.demon.nl>"
|
||||||
say " "
|
print_screen_output " "
|
||||||
say "This program is free software; you can redistribute it and/or modify"
|
print_screen_output "This program is free software; you can redistribute it and/or modify"
|
||||||
say "it under the terms of the GNU General Public License as published by"
|
print_screen_output "it under the terms of the GNU General Public License as published by"
|
||||||
say "the Free Software Foundation; either version 3 of the License, or"
|
print_screen_output "the Free Software Foundation; either version 3 of the License, or"
|
||||||
say "(at your option) any later version."
|
print_screen_output "(at your option) any later version."
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -558,7 +558,7 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ALLUP=1
|
ALLUP=1
|
||||||
dbg "ALLUP=1 : inxi up and running.."
|
debug_script "ALLUP=1 : inxi up and running.."
|
||||||
|
|
||||||
HN=$(hostname)
|
HN=$(hostname)
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ elif (( ${#DISTGLOB[@]} > 1 ))
|
||||||
then
|
then
|
||||||
for I in $DIST_DERIV $DIST_MAIN
|
for I in $DIST_DERIV $DIST_MAIN
|
||||||
do
|
do
|
||||||
# Only echo works with ${var[@]}, not say() or dbg()
|
# Only echo works with ${var[@]}, not print_screen_output() or debug_script()
|
||||||
# This is a known bug, search for the word "strange" inside comments
|
# This is a known bug, search for the word "strange" inside comments
|
||||||
# echo "I='$I' DISTGLOB[@]='${DISTGLOB[@]}'"
|
# echo "I='$I' DISTGLOB[@]='${DISTGLOB[@]}'"
|
||||||
if [[ " ${DISTGLOB[@]} " == *" $I "* ]]
|
if [[ " ${DISTGLOB[@]} " == *" $I "* ]]
|
||||||
|
@ -774,7 +774,7 @@ then
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##say "$HDDMOD" ; exit
|
##print_screen_output "$HDDMOD" ; exit
|
||||||
if ((CAP))
|
if ((CAP))
|
||||||
then
|
then
|
||||||
HDDCAP1="$((CAP/2))"
|
HDDCAP1="$((CAP/2))"
|
||||||
|
@ -782,7 +782,7 @@ fi
|
||||||
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
|
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
|
||||||
HDDCAP2=$( gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions )
|
HDDCAP2=$( gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions )
|
||||||
|
|
||||||
##say "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
|
##print_screen_output "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
|
||||||
HDD=0
|
HDD=0
|
||||||
for I in ${!HDDCAP*}
|
for I in ${!HDDCAP*}
|
||||||
do
|
do
|
||||||
|
@ -934,16 +934,16 @@ then
|
||||||
LNINTRO=$(printf "${C1}%-${INDENT}s${C2} " "OS/Kernel")
|
LNINTRO=$(printf "${C1}%-${INDENT}s${C2} " "OS/Kernel")
|
||||||
fi
|
fi
|
||||||
LNINTRO="$LNINTRO$(echo -ne "${C2}$OSKERN ${CN}[ ${C1}$DISTRO ${CN}]")"
|
LNINTRO="$LNINTRO$(echo -ne "${C2}$OSKERN ${CN}[ ${C1}$DISTRO ${CN}]")"
|
||||||
say "$LNINTRO"
|
print_screen_output "$LNINTRO"
|
||||||
|
|
||||||
##say "CPU[0]=\"${CPU[0]}\""
|
##print_screen_output "CPU[0]=\"${CPU[0]}\""
|
||||||
IFS=","; CPUTMP=(${CPU[0]}); IFS="$OIFS"
|
IFS=","; CPUTMP=(${CPU[0]}); IFS="$OIFS"
|
||||||
# Strange (and also some expected) behavior encountered.
|
# Strange (and also some expected) behavior encountered.
|
||||||
# If say() uses $1 as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
|
# If print_screen_output() uses $1 as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
|
||||||
# will output only <text1> and the first element of ARR. That "@" splits in elements and "*" _doesn't_, is to be expected.
|
# will output only <text1> and the first element of ARR. That "@" splits in elements and "*" _doesn't_, is to be expected.
|
||||||
# However, that text2 is consecutively truncated is somewhat strange, so take note. This has been confirmed by #bash on freenode.
|
# However, that text2 is consecutively truncated is somewhat strange, so take note. This has been confirmed by #bash on freenode.
|
||||||
# The above mentioned only emerges when using the debugging markers below
|
# The above mentioned only emerges when using the debugging markers below
|
||||||
##say "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
|
##print_screen_output "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
|
||||||
|
|
||||||
if [[ -z ${CPUTMP[2]} ]]
|
if [[ -z ${CPUTMP[2]} ]]
|
||||||
then
|
then
|
||||||
|
@ -963,7 +963,7 @@ then
|
||||||
LNCPU=$(printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")")
|
LNCPU=$(printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")")
|
||||||
fi
|
fi
|
||||||
LNCPU=$(printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]")
|
LNCPU=$(printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]")
|
||||||
say "$LNCPU"
|
print_screen_output "$LNCPU"
|
||||||
|
|
||||||
for ((I=1;I<${#CPU[@]}-1;I++))
|
for ((I=1;I<${#CPU[@]}-1;I++))
|
||||||
do
|
do
|
||||||
|
@ -976,7 +976,7 @@ then
|
||||||
LNCPU=$( printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")" )
|
LNCPU=$( printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")" )
|
||||||
fi
|
fi
|
||||||
LNCPU=$( printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]" )
|
LNCPU=$( printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]" )
|
||||||
say "$LNCPU"
|
print_screen_output "$LNCPU"
|
||||||
if [[ $I -gt 10 ]]
|
if [[ $I -gt 10 ]]
|
||||||
then
|
then
|
||||||
break
|
break
|
||||||
|
@ -992,12 +992,12 @@ then
|
||||||
LNGFX="${LNGFX}$(echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})")"
|
LNGFX="${LNGFX}$(echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say "$LNGFX"
|
print_screen_output "$LNGFX"
|
||||||
I=1
|
I=1
|
||||||
while [[ -n ${GFX[I]} && $I -le 3 ]]
|
while [[ -n ${GFX[I]} && $I -le 3 ]]
|
||||||
do
|
do
|
||||||
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
|
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
|
||||||
say "$LNGFX"
|
print_screen_output "$LNGFX"
|
||||||
(( I++ ))
|
(( I++ ))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -1043,10 +1043,10 @@ then
|
||||||
if [[ -n ${LNNET[@]} ]]
|
if [[ -n ${LNNET[@]} ]]
|
||||||
then
|
then
|
||||||
I=0
|
I=0
|
||||||
say "$(printf "${C1}%-${INDENT}s${C2} %s" "Network cards" "${LNNET[I]}")"
|
print_screen_output "$(printf "${C1}%-${INDENT}s${C2} %s" "Network cards" "${LNNET[I]}")"
|
||||||
while [[ -n ${LNNET[++I]} ]]
|
while [[ -n ${LNNET[++I]} ]]
|
||||||
do
|
do
|
||||||
say "$(printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}")"
|
print_screen_output "$(printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}")"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -1083,7 +1083,7 @@ then
|
||||||
then
|
then
|
||||||
LNLAST="${LNLAST}$( echo -ne "${NORMAL}" )"
|
LNLAST="${LNLAST}$( echo -ne "${NORMAL}" )"
|
||||||
fi
|
fi
|
||||||
say "$LNLAST"
|
print_screen_output "$LNLAST"
|
||||||
else # (IF VBL > 1 ... ELSE)
|
else # (IF VBL > 1 ... ELSE)
|
||||||
#cscheme 12
|
#cscheme 12
|
||||||
if ! ((IBSHELL))
|
if ! ((IBSHELL))
|
||||||
|
@ -1095,7 +1095,7 @@ else # (IF VBL > 1 ... ELSE)
|
||||||
LNSHORT=$(echo -ne "${C1}CPU${CN}[${C2}${CPUMODEL} clocked at ${CPUCLOCK}${CN}] ${C1}Kernel${CN}[${C2}${OSKERN}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${UPT}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${MEM}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${HDD}($HDDUSG)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${PROC}${FL1}${CN}]")
|
LNSHORT=$(echo -ne "${C1}CPU${CN}[${C2}${CPUMODEL} clocked at ${CPUCLOCK}${CN}] ${C1}Kernel${CN}[${C2}${OSKERN}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${UPT}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${MEM}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${HDD}($HDDUSG)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${PROC}${FL1}${CN}]")
|
||||||
((SHOWIRC)) && LNSHORT="${LNSHORT}$(echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]")"
|
((SHOWIRC)) && LNSHORT="${LNSHORT}$(echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]")"
|
||||||
((SCHEME)) && LNSHORT="${LNSHORT}$(echo -ne "$NORMAL")"
|
((SCHEME)) && LNSHORT="${LNSHORT}$(echo -ne "$NORMAL")"
|
||||||
say "$LNSHORT"
|
print_screen_output "$LNSHORT"
|
||||||
fi # (IF VBL > 1)
|
fi # (IF VBL > 1)
|
||||||
|
|
||||||
if ((IBSHELL && SCHEME))
|
if ((IBSHELL && SCHEME))
|
||||||
|
|
Loading…
Reference in a new issue