inxi :: programming conventions
Page Version: 1.0 Page Updated: 2015-08-24/pointer to updated page: 2020-11-21
This page is obsolete, it was about pre Perl Bash/Gawk inxi 2.x, not the 3.x Perl version!!
For an updated version, check out inxi core philosophy/programming concepts instead. While mostly about why inxi internally looks, acts, and works the way it does, that should be fairly useful for potential contributors. The actual programming conventions should be quite obvous once you open the file and look at it.
If you would like to submit patches for inxi, read and understand these conventions. Patches not following these rules will be ignored.
As with all 'rules' there are exceptions, these are noted where used.
Basic Formatting and Structural Rules
- Indentation: TABS
- Do not use `....` (back quotes; aka: back tick; outdated bash style), those are totally non-reabable, use $(....) (parens; new bash style).
- Back quotes start a new shell.
- Parenthesis run in current shell.
- Do not use one liner flow controls. Readability is more important.
- The ONLY time you should use ';' (semi-colon) is in this single case:
if [[ condition ]];then. - Never use compound 'if': ie:
if [[ condition ]] && statement. - Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
- Always use quotes, double or single, for all string values.
- All new code/methods must be in a function.
- For all boolean tests, use 'true' / 'false'.
- !! Do NOT use 0 or 1 unless it's a function return.
- Avoid complicated tests in the if condition itself.
- To 'return' a value in a function, use 'echo '.
- For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
- This method lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
Variables and Function Naming:
- All functions should follow standard naming--verb adjective noun.
- ie, get_cpu_data
- All variables MUST be initialized / declared explicitly.
- All variables should clearly explain what they are, except counters like i, j.
- Each word of variable or function must be separated by '_' (underscore) (camel form).
- use_this_style
- Global variables are 'UPPER CASE', at top of script.
- ie, SOME_VARIABLE=''
- Local variables are 'lower case' and declared at the top of the function.
- ie, some_variable=''
- Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
- ie, Some_Variable?
- Booleans should start with 'b_' (local) or 'B_' (global) and state clearly what is being tested.
- Arrays should start with 'a_' (local) or 'A_' (global).
Special Notes:
- The color variable ${C2} must always be followed by a space unless you know what character is going to be next for certain. Otherwise irc color codes can be accidentally activated or altered.
- For native script konversation support (check distro for correct konvi scripts path):
'KDE3' ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi 'KDE4' ln -s <path to inxi> /usr/share/kde4/apps/konversation/scripts/inxi
- DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.