mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
refactored more, rearranged utility functions
This commit is contained in:
parent
cde859ac3b
commit
6779d27964
71
inxi
71
inxi
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
#### Script Name: inxi
|
||||
#### version: 0.1.22
|
||||
#### version: 0.1.23
|
||||
#### Date: October 27 2008
|
||||
########################################################################
|
||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||
|
@ -122,26 +122,9 @@ HN=$(hostname)
|
|||
#### UTILITY FUNCTIONS
|
||||
########################################################################
|
||||
|
||||
# inxi speaks through here. When run by Konversation, use DCOP
|
||||
print_screen_output()
|
||||
{
|
||||
if (( DEBUG > 5 ))
|
||||
then
|
||||
if ((KONVI))
|
||||
then
|
||||
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
|
||||
else
|
||||
echo "konvi='$konvi' saying : '$@'"
|
||||
fi
|
||||
fi
|
||||
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
|
||||
if (( KONVI ))
|
||||
then
|
||||
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
|
||||
else
|
||||
echo -ne "$1\n"
|
||||
fi
|
||||
}
|
||||
#### -------------------------------------------------------------------
|
||||
#### error handler and debugger
|
||||
#### -------------------------------------------------------------------
|
||||
|
||||
# Error handling
|
||||
error_handler()
|
||||
|
@ -199,6 +182,31 @@ script_debugger()
|
|||
fi
|
||||
}
|
||||
|
||||
#### -------------------------------------------------------------------
|
||||
#### print / output cleaners
|
||||
#### -------------------------------------------------------------------
|
||||
|
||||
# inxi speaks through here. When run by Konversation, use DCOP
|
||||
print_screen_output()
|
||||
{
|
||||
if (( DEBUG > 5 ))
|
||||
then
|
||||
if ((KONVI))
|
||||
then
|
||||
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
|
||||
else
|
||||
echo "konvi='$konvi' saying : '$@'"
|
||||
fi
|
||||
fi
|
||||
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
|
||||
if (( KONVI ))
|
||||
then
|
||||
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
|
||||
else
|
||||
echo -ne "$1\n"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_erroneous_chars()
|
||||
{
|
||||
## this removes newline and pipes
|
||||
|
@ -217,6 +225,18 @@ remove_erroneous_chars()
|
|||
# gawk 'BEGIN { RS="" } { gsub(/\n$/,""); gsub(/\n/," "); gsub(/^ *| *$/, ""); gsub(/ +/, " "); printf $0 }' "$1"
|
||||
# }
|
||||
|
||||
# Enforce boilerplate and buzzword filters
|
||||
sanitize()
|
||||
{
|
||||
# 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!
|
||||
# Using weak quotes instead, or use '"..."'
|
||||
echo "$2" | gawk "BEGIN { IGNORECASE=1 } { gsub(/${!1}/,\"\"); gsub(/ [ ]+/,\" \"); gsub(/^ +| +$/,\"\"); print }"
|
||||
}
|
||||
|
||||
#### -------------------------------------------------------------------
|
||||
#### basic tests
|
||||
#### -------------------------------------------------------------------
|
||||
|
||||
# Determine if any of the absolutely necessary tools are absent
|
||||
check_script_depends()
|
||||
{
|
||||
|
@ -500,15 +520,6 @@ get_parameters()
|
|||
done
|
||||
}
|
||||
|
||||
# Enforce boilerplate and buzzword filters
|
||||
sanitize()
|
||||
{
|
||||
# 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!
|
||||
# Using weak quotes instead, or use '"..."'
|
||||
echo "$2" | gawk "BEGIN { IGNORECASE=1 } { gsub(/${!1}/,\"\"); gsub(/ [ ]+/,\" \"); gsub(/^ +| +$/,\"\"); print }"
|
||||
}
|
||||
|
||||
|
||||
########################################################################
|
||||
#### MAIN FUNCTIONS
|
||||
########################################################################
|
||||
|
|
Loading…
Reference in a new issue