more refactoring, some bug fixes that made layout display wrong in editors

This commit is contained in:
inxi-svn 2008-10-28 02:48:05 +00:00
parent 04674b0e72
commit a5dd519b0f

141
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.1.5 #### version: 0.1.6
#### 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
@ -146,7 +146,7 @@ error_handler()
print_screen_output "$SCRIPT_NAME: large flood danger, debug buffer full!" print_screen_output "$SCRIPT_NAME: large flood danger, debug buffer full!"
;; ;;
3) 3)
print_screen_output "$SCRIPT_NAME: error in colorscheme, or unknown parameter: $2" print_screen_output "$SCRIPT_NAME: error in colorscheme - unsupported number: $2"
;; ;;
4) 4)
print_screen_output "$SCRIPT_NAME: unknown verbosity level $2" print_screen_output "$SCRIPT_NAME: unknown verbosity level $2"
@ -157,6 +157,9 @@ error_handler()
6) 6)
print_screen_output "$SCRIPT_NAME: /proc not found! Quitting..." print_screen_output "$SCRIPT_NAME: /proc not found! Quitting..."
;; ;;
7)
print_screen_output "$SCRIPT_NAME: unknown parameter: $2"
;;
*) *)
print_screen_output "$SCRIPT_NAME: error unknown: $@" print_screen_output "$SCRIPT_NAME: error unknown: $@"
set -- 99 set -- 99
@ -460,12 +463,16 @@ get_parameters()
exit 0 exit 0
;; ;;
*) *)
# these will need to be converted to standard type options
echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1" echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1"
if ! ((CSCHEME)) if ! ((CSCHEME))
then then
set_color_scheme "$1" set_color_scheme "$1"
fi fi
;; ;;
# *)
# error_handler 7 "$1"
# ;;
esac esac
shift shift
done done
@ -689,7 +696,7 @@ CPUTMP=(${CPU[0]})
IFS="$OIFS" IFS="$OIFS"
# For the short line # For the short line
CPUMODEL="${CPU2}${CPU2+ }${CPUTMP[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2 CPUMODEL="${CPU2}${CPU2+ }${CPUTMP[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2
CPUCLOCK="${CPU[${#CPU[@]}-1]}" # old CPU3 CPUCLOCK="$CPU[${#CPU[@]}-1]" # old CPU3
CPUFLAGS="${CPUTMP[3]}" # old CPU4 CPUFLAGS="${CPUTMP[3]}" # old CPU4
# nx = AMD stack protection extensions # nx = AMD stack protection extensions
# lm = Intel 64bit extensions # lm = Intel 64bit extensions
@ -747,7 +754,8 @@ if [[ -e /proc/scsi/scsi ]]
then then
# Silly sata detection, will also pick up usb sticks, and it is all I will put into infobash. if you want more, infoperl is on # Silly sata detection, will also pick up usb sticks, and it is all I will put into infobash. if you want more, infoperl is on
# the way :) # the way :)
IFS=$'\n'; THDD=($(gawk ' IFS=$'\n'
THDD=($(gawk '
BEGIN { IGNORECASE=1 } BEGIN { IGNORECASE=1 }
/host/ { /host/ {
getline a[$0] getline a[$0]
@ -793,7 +801,7 @@ do
done done
if ((HDD)) if ((HDD))
then then
HDDUSG=$(df | gawk ' HDDUSG=$( df | gawk '
p { p {
if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) { if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) {
if (NF == 1) { if (NF == 1) {
@ -806,7 +814,7 @@ then
} }
/^Filesystem/ { p++ } /^Filesystem/ { p++ }
END { print c } END { print c }
') ' )
HDDUSG="$((HDDUSG*100/HDD))%used" HDDUSG="$((HDDUSG*100/HDD))%used"
HDD="$(($HDD*1024/1000**3))GB" HDD="$(($HDD*1024/1000**3))GB"
else else
@ -814,13 +822,13 @@ else
HDD="unknown.." HDD="unknown.."
fi fi
MEM=$(gawk ' MEM=$( gawk '
/^MemTotal:/ { tot = $2 } /^MemTotal:/ { tot = $2 }
/^(MemFree|Buffers|Cached):/ { notused+=$2 } /^(MemFree|Buffers|Cached):/ { notused+=$2 }
END { END {
used = tot-notused used = tot-notused
printf("%.1f/%.1fMB\n", used/1024, tot/1024) printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo) }' /proc/meminfo )
PROC="$(( $( ps aux | wc -l ) - 1 ))" PROC="$(( $( ps aux | wc -l ) - 1 ))"
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' ) UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
@ -850,30 +858,36 @@ then
print(line) print(line)
} }
') ')
[[ -z $RES ]] && RES=$(xdpyinfo | gawk '/dimensions/ { print $2 }') if [[ -z $RES ]]
then
RES=$( xdpyinfo | gawk '/dimensions/ { print $2 }' )
fi
# X vendor and version detection. # X vendor and version detection.
XVENDOR=$(xdpyinfo | gawk -F': +' ' XVENDOR=$( xdpyinfo | gawk -F': +' '
BEGIN { IGNORECASE=1 } BEGIN { IGNORECASE=1 }
/vendor string/ { /vendor string/ {
gsub(/the|,|inc|foundation|project|coorperation/, "", $2) gsub(/the|,|inc|foundation|project|coorperation/, "", $2)
gsub(/^ +| +$/, "", $2); gsub(/ +/," ",$2) gsub(/^ +| +$/, "", $2); gsub(/ +/," ",$2)
print $2 print $2
} }
') ' )
# new method added since radeon and X.org and the disappearance of <X server name> version : ...etc # new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
# Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2 # Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
# A failover mechanism is in place. (if $XVERNUM is empty, the release number is parsed instead) # A failover mechanism is in place. (if $XVERNUM is empty, the release number is parsed instead)
XVERNUM=$(xdpyinfo | awk '/version:/ { print $NF }') XVERNUM=$( xdpyinfo | awk '/version:/ { print $NF }' )
[[ -z $XVERNUM ]] && XVERNUM=$(xdpyinfo | gawk -F': +' ' if [[ -z $XVERNUM ]]
BEGIN { IGNORECASE=1 } then
/vendor release number/ { XVERNUM=$(xdpyinfo | gawk -F': +' '
gsub(/0+$/,"",$2) BEGIN { IGNORECASE=1 }
gsub(/0+/,".",$2) /vendor release number/ {
print $2 gsub(/0+$/,"",$2)
} gsub(/0+/,".",$2)
') print $2
}
')
fi
#X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }' #X -version 2>&1 | gawk '/^X Window System Version/ { print $5 }'
#This method could be used in the future to detect X when X is not running, #This method could be used in the future to detect X when X is not running,
@ -881,7 +895,7 @@ then
XVER="$XVENDOR $XVERNUM" XVER="$XVENDOR $XVERNUM"
IFS=$'\n' IFS=$'\n'
GLX=($(glxinfo | gawk -F ': ' ' GLX=( $( glxinfo | gawk -F ': ' '
function join(arr, sep) { function join(arr, sep) {
s="" s=""
i=flag=0 i=flag=0
@ -911,33 +925,40 @@ then
END { END {
printf("%s\n%s\n%s\n", join(a,", "), join(b,", "), join(c,", ")) printf("%s\n%s\n%s\n", join(a,", "), join(b,", "), join(c,", "))
} }
')) ' ) )
IFS="$OIFS" IFS="$OIFS"
GLXR="${GLX[0]}"; GLXV="${GLX[1]}"; GLXDR="${GLX[2]}" GLXR="${GLX[0]}"
GLXV="${GLX[1]}"
GLXDR="${GLX[2]}"
# GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}') # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
# GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}') # GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}')
[[ -z $GLXR || -z $GLXV ]] && MESA=1 if [[ -z $GLXR || -z $GLXV ]]
then
MESA=1
fi
AGPMOD=$(gawk '/agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' /proc/modules) AGPMOD=$(gawk '/agp/ && !/agpgart/ && $3 > 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' /proc/modules)
else else
RES=$(stty -F $(readlink /proc/$PPID/fd/0) size | gawk '{ print $2"x"$1 }') RES=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
RUNLVL=$(runlevel | gawk '{ print $2 }') RUNLVL=$( runlevel | gawk '{ print $2 }' )
fi fi
# (IF VBL > 1) # (IF VBL > 1)
if ((VBL)) if ((VBL))
then then
if ((SHOW_HOST)) if ((SHOW_HOST))
then then
LNINTRO=$(printf "${C1}%-${INDENT}s${C2} \"%s\"${C1} %s " "Host/Kernel/OS" "$HN" "running") LNINTRO=$( printf "${C1}%-${INDENT}s${C2} \"%s\"${C1} %s " "Host/Kernel/OS" "$HN" "running" )
else else
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}]" )"
print_screen_output "$LNINTRO" print_screen_output "$LNINTRO"
##print_screen_output "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 print_screen_output() 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.
@ -957,15 +978,15 @@ then
# Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge # Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge
unset CPUNUM unset CPUNUM
fi fi
LNCPU=$(printf "${C1}%-${INDENT}s${C2} %s" "CPU Info" "${CPUNUM}${CPUNUM+ }${CPUTMP[0]}") LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" "CPU Info" "${CPUNUM}${CPUNUM+ }${CPUTMP[0]}" )
if [[ $VBL -ge 3 ]] if [[ $VBL -ge 3 ]]
then 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" "]" )
print_screen_output "$LNCPU" print_screen_output "$LNCPU"
for ((I=1;I<${#CPU[@]}-1;I++)) for (( I=1; I < ${#CPU[@]}-1; I++))
do do
IFS="," IFS=","
CPUTMP=(${CPU[I]}) CPUTMP=(${CPU[I]})
@ -984,12 +1005,12 @@ then
done done
LNGFX=$(printf "${C1}%-${INDENT}s${C2} %s" "Videocard" "${GFX[0]}") LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" "Videocard" "${GFX[0]}" )
if ((X)) if ((X))
then then
LNGFX="${LNGFX}$(echo -ne "${C1} $XVER ${CN}[${C2} ${RES} ${CN}]")" LNGFX="${LNGFX}$( echo -ne "${C1} $XVER ${CN}[${C2} ${RES} ${CN}]" )"
else else
LNGFX="${LNGFX}$(echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})")" LNGFX="${LNGFX}$( echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})" )"
fi fi
print_screen_output "$LNGFX" print_screen_output "$LNGFX"
@ -1043,21 +1064,21 @@ then
if [[ -n ${LNNET[@]} ]] if [[ -n ${LNNET[@]} ]]
then then
I=0 I=0
print_screen_output "$(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
print_screen_output "$(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
# Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch! # Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
LNLAST=$(echo -ne "${C1}Processes${C2} ${PROC}${CN} | ${C1}Uptime${C2} ${UPT}${CN} | ${C1}Memory${C2} ${MEM}${CN}") LNLAST=$( echo -ne "${C1}Processes${C2} ${PROC}${CN} | ${C1}Uptime${C2} ${UPT}${CN} | ${C1}Memory${C2} ${MEM}${CN}" )
if [[ $VBL -ge 2 ]] if [[ $VBL -ge 2 ]]
then then
LNLAST="${LNLAST}$(echo -ne " | ${C1}HDD${C2} ${HDDMOD} ${C1}Size${C2} ${HDD} (${HDDUSG})${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}HDD${C2} ${HDDMOD} ${C1}Size${C2} ${HDD} (${HDDUSG})${CN}" )"
else else
LNLAST="${LNLAST}$(echo -ne " | ${C1}HDD Size${C2} ${HDD} (${HDDUSG})${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}HDD Size${C2} ${HDD} (${HDDUSG})${CN}" )"
fi fi
if ((X)) && ! ((MESA)) if ((X)) && ! ((MESA))
@ -1088,13 +1109,37 @@ else # (IF VBL > 1 ... ELSE)
#set_color_scheme 12 #set_color_scheme 12
if ! ((IBSHELL)) if ! ((IBSHELL))
then then
for I in $C1 $C2 $CN ; do case "$I" in "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN") BGBLACK=1 ;; esac ; done for I in $C1 $C2 $CN
((BGBLACK)) && { for I in C1 C2 CN ; do [[ "${!I}" = "$NORMAL" ]] && declare $I="${!I}15,1" || declare $I="${!I},1" ; done ; } do
#C1="${C1},1"; C2="${C2},1"; CN="${CN},1" case "$I" in
"$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN") BGBLACK=1
;;
esac
done
if ((BGBLACK))
then
for I in C1 C2 CN
do
if [[ "${!I}" = "$NORMAL" ]]
then
declare $I="${!I}15,1"
else
declare $I="${!I},1"
fi
done
#C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
fi
fi
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}]" )
if ((SHOW_IRC))
then
LNSHORT="${LNSHORT}$( echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]" )"
fi
if ((SCHEME))
then
LNSHORT="${LNSHORT}$( echo -ne "$NORMAL" )"
fi fi
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}]")
((SHOW_IRC)) && LNSHORT="${LNSHORT}$(echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]")"
((SCHEME)) && LNSHORT="${LNSHORT}$(echo -ne "$NORMAL")"
print_screen_output "$LNSHORT" print_screen_output "$LNSHORT"
fi # (IF VBL > 1) fi # (IF VBL > 1)