From 48fd02fb37d85b8c75fc1d21f0e10ba6bc12382c Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 16 Mar 2014 13:46:15 +0100 Subject: [PATCH] Yet another inxi version bump This fixes the term-related warnings the last version had. --- data/scripts/inxi | 95 ++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/data/scripts/inxi b/data/scripts/inxi index a7c2528d..0c55bb8e 100755 --- a/data/scripts/inxi +++ b/data/scripts/inxi @@ -1,7 +1,7 @@ #!/usr/bin/env bash ######################################################################## #### Script Name: inxi -#### Version: 2.1.1 +#### Version: 2.1.2 #### Date: 2014-03-14 #### Patch Number: 00 ######################################################################## @@ -494,15 +494,17 @@ COLS_MAX='' TERM_COLUMNS=80 TERM_LINES=100 -# http://stackoverflow.com/questions/1780483/lines-and-columns-environmental-variables-lost-in-a-script -if [[ -n $( type -p tput ) ]];then - TERM_COLUMNS=$(tput cols) - TERM_LINES=$(tput lines) -fi -# double check, just in case it's missing functionality or whatever -if [[ -n ${TERM_COLUMNS##[0-9]*} ]];then - TERM_COLUMNS=80 - TERM_LINES=100 +## sometimes will trigger an error (mageia) if not in shell +if [[ $B_RUNNING_IN_SHELL == 'true' ]];then + if [[ -n $( type -p tput ) ]];then + TERM_COLUMNS=$(tput cols) + TERM_LINES=$(tput lines) + fi + # double check, just in case it's missing functionality or whatever + if [[ -n ${TERM_COLUMNS##[0-9]*} ]];then + TERM_COLUMNS=80 + TERM_LINES=100 + fi fi # Only for legacy user config files se we can test and convert the var name @@ -672,8 +674,8 @@ main() fi COLS_MAX=$COLS_MAX_IRC fi - COLS_INNER=$(( $COLS_MAX - $INDENT - 4 )) - + + COLS_INNER=$(( $COLS_MAX - $INDENT - 1 )) # Check for dependencies BEFORE running ANYTHING else except above functions # Not all distro's have these depends installed by default. Don't want to run # this if the user is requesting to see this information in the first place @@ -2010,7 +2012,8 @@ print_screen_output() { eval $LOGFS # the double quotes are needed to avoid losing whitespace in data when certain output types are used - local print_data="$( echo -e "$1" )" + # trim off whitespace at end + local print_data="$( echo -e "$1" )" # just using basic debugger stuff so you can tell which thing is printing out the data. This # should help debug kde 4 konvi issues when that is released into sid, we'll see. Turning off @@ -2053,7 +2056,8 @@ print_screen_output() create_print_line() { eval $LOGFS - printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2" + local line=$2 + printf "${C1}%-${INDENT}s${C2} %s" "$1" "$line" eval $LOGFE } @@ -8752,7 +8756,7 @@ get_weather_data() # returns count of string length minus colors calculate_line_length() { - local string="$1" + local string=$1 # ansi:  irc: \x0312 string=$( sed -e "s/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g" -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string ) count=${#string} @@ -8808,8 +8812,7 @@ process_cpu_flags() # sse, sse2, pni = sse1,2,3,4,5 gfx extensions # svm = AMD pacifica virtualization extensions # vmx = Intel IVT (vanderpool) virtualization extensions - cpu_flags=$( - echo "$cpu_flags_working" | gawk ' + cpu_flags=$( gawk ' BEGIN { RS=" " count = 0 @@ -8838,7 +8841,7 @@ process_cpu_flags() } } print flag_string - }' ) + }' <<< "$cpu_flags_working" ) #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' ')) if [[ -z $cpu_flags ]];then @@ -9176,7 +9179,7 @@ print_cpu_data() local a_cpu_working='' cpu_model='' cpu_clock='' cpu_null_error='' local cpc_plural='' cpu_count_print='' model_plural='' cpu_data_string='' local cpu_physical_count='' cpu_core_count='' cpu_core_alpha='' cpu_type='' - local cpu_2_data='' + local cpu_2_data='' line_starter='' ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\"" # Array A_CPU_DATA always has one extra element: max clockfreq found. @@ -9215,9 +9218,9 @@ print_cpu_data() cpu_count_print="$cpu_physical_count " model_plural='s' fi - + line_starter="CPU$cpc_plural:" cpu_data_string="${cpu_count_print}${cpu_core_alpha} core" - cpu_data=$( create_print_line "CPU$cpc_plural:" "${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" ) + cpu_data="${C1}${cpu_data_string}${C2} ${a_cpu_working[0]}$model_plural (${cpu_type})" if [[ $B_SHOW_CPU == 'true' ]];then # update for multicore, bogomips x core count. if [[ $B_EXTRA_DATA == 'true' ]];then @@ -9226,6 +9229,7 @@ print_cpu_data() # echo $cpu_core_count $cpu_physical_count if [[ -n ${a_cpu_working[4]} ]];then bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$(( $cpu_core_count * $cpu_physical_count ))" ) + bmip_data=${bmip_data%.*} fi # else # bmip_data="${a_cpu_working[4]}" @@ -9257,6 +9261,7 @@ print_cpu_data() if [[ ${a_cpu_working[6]} == 'true' ]];then flag_feature='features' fi + cpu_flags="${C1}$flag_feature$SEP3${C2} $cpu_flags " fi fi @@ -9272,25 +9277,30 @@ print_cpu_data() if [[ ${#A_CPU_DATA[@]} -gt 2 && $B_SHOW_CPU == 'true' ]];then cpu_clock_speed='' # null < verbosity level 5 else - cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}" + cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]%.*} MHz${CN}" fi cpu_2_data="$cpu_2_data$cpu_clock_speed" else if [[ $BSD_TYPE == 'bsd' && $B_ROOT != 'true' ]];then cpu_null_error=' No permissions for sysctl use?' fi - cpu_data=$( create_print_line "CPU:" "${C2}No CPU data available.$cpu_null_error" ) + cpu_data="${C2}No CPU data available.$cpu_null_error" fi - # echo ln: $( calculate_line_length "$cpu_data $cpu_2_data" ) - # echo icols: $COLS_INNER - # echo tc: $TERM_COLUMNS - # echo :$cpu_2_data: +# echo $cpu_data $cpu_2_data +# echo ln: $( calculate_line_length "$cpu_data $cpu_2_data" ) +# echo cpl: $( create_print_line "$line_starter" "${cpu_2_data}" ): +# echo icols: $COLS_INNER +# echo tc: $TERM_COLUMNS + # echo :${cpu_2_data}: if [[ -n $cpu_2_data && $( calculate_line_length "$cpu_data $cpu_2_data" ) -gt $COLS_INNER ]];then + cpu_data=$( create_print_line "$line_starter" "${cpu_data}" ) + line_starter='' print_screen_output "$cpu_data" - cpu_data=$( create_print_line " " "$cpu_2_data" ) + cpu_data=$( create_print_line " " "${cpu_2_data}" ) print_screen_output "$cpu_data" else - print_screen_output "$cpu_data $cpu_2_data" + cpu_data=$( create_print_line "$line_starter" "${cpu_data}" ) + print_screen_output "$cpu_data ${cpu_2_data}" fi # we don't this printing out extra line unless > 1 cpu core # note the numbering, the last array item is the min/max/not found for cpu speeds @@ -9301,7 +9311,7 @@ print_cpu_data() a_cpu_working=(${A_CPU_DATA[i]}) IFS="$ORIGINAL_IFS" # note: the first iteration will create a first space, for color code separation below - cpu_multi_clock_data="$cpu_multi_clock_data ${C1}$(( i + 1 )):${C2} ${a_cpu_working[1]} MHz${CN}" + cpu_multi_clock_data="$cpu_multi_clock_data ${C1}$(( i + 1 )):${C2} ${a_cpu_working[1]%.*} MHz${CN}" # someone actually appeared with a 16 core system, so going to stop the cpu core throttle # if this had some other purpose which we can't remember we'll add it back in #if [[ $i -gt 10 ]];then @@ -9333,24 +9343,25 @@ print_cpu_flags_full() if [[ $2 == 'true' ]];then flag_feature='Features' fi + line_starter="CPU $flag_feature$SEP3" + starter_length=$(( ${#line_starter} + 1 )) + line_starter="${C1}$line_starter${C2} " + line_length=$(( $COLS_INNER - $starter_length )) # build the flag line array for flag in $cpu_flags_full do temp_string="$flag_string$spacer$flag" spacer=' ' # handle inner line starter - if [[ $counter -eq 0 ]];then - line_length=$(( $COLS_INNER - $starter_length )) - else + if [[ $counter -gt 0 ]];then line_length=$COLS_INNER fi - if [[ ${#temp_string} -gt $line_length ]];then - a_cpu_flags[$counter]=$temp_string - flag_string='' - spacer='' - (( counter++ )) - else + if [[ $line_length -ge ${#temp_string} ]];then flag_string=$temp_string + else + a_cpu_flags[$counter]=$flag_string + flag_string=$flag + (( counter++ )) fi temp_string='' done @@ -9360,9 +9371,7 @@ print_cpu_flags_full() # then print it out for (( i=0; i < ${#a_cpu_flags[@]};i++ )) do - if [[ $i -eq 0 ]];then - line_starter="${C1}CPU $flag_feature$SEP3${C2} " - else + if [[ $i -gt 0 ]];then line_starter='' fi flag_data=$( create_print_line " " "$line_starter${a_cpu_flags[$i]}" ) @@ -11029,7 +11038,7 @@ print_sensors_data() gpu_temp=$( get_gpu_temp_data ) # dump the unneeded screen data for single gpu systems if [[ $( wc -w <<< $gpu_temp ) -eq 1 && $B_EXTRA_DATA != 'true' ]];then - gpu_temp=$( cut -d ':' -f 2 <<< $gpu_temp ) + gpu_temp=${gpu_temp#*:} fi if [[ -n $gpu_temp ]];then gpu_temp="${C1}gpu$SEP3${C2} ${gpu_temp} " -- 2.20.1