Search code examples
shellorg-modecode-snippets

How to show inxi output in an org-mode snippet


I need to add a snippet to my org-mode document that shows the output from inxi. I tried with

#+BEGIN_SRC sh
#!/usr/bin/bash

inxi -Fxxxza --no-host

#+END_SRC

but the output is messy and not what it is shown normally on shell. E.g.

| 12System:                                      | 12Kernel                       | 4.19.126-1-MANJARO | x86_64           | 12bits          | 64             | 12compiler  | gcc             | 12v      | 10.1.0          |             |                  |              |                |           |          |      |    |

Is there a way to make it so it appears as close as the output I get on bash?

Thank you in advance!


Solution

  • First, you want to make sure you aren't using legacy inxi, that's pre 3.x, though the legacy version works ok, but doesn't have many of the features designed to handle these exact scenarios. Given you are using --no-host, I think but am not sure that means you are using 3.x generation inxi.

    If inxi can't detect it's running in a terminal or shell, it defaults to assuming it's running in an IRC client, which alters the behaviors.

    You can see easily if this is the case if the output contains the ':' as key: value separator, if it doesn't, it thinks it's in an IRC client. If it's a legacy inxi however, these behaviors aren't as predictable, so you want to make sure you are using current inxi (3.1.04 is current latest).

    The --tty flag tells inxi to act as if it's in a terminal even though it can't detect that it is, that's to handle cases like yours where inxi is being used inside of some other program directly.

    The -c0 [that's zero] flag tells it to remove all color codes.

    If you are using current inxi, or at least, post 3.x inxi, you can very accurately assign the output width using the -y flag, and -y 80 gives very readable 80 column results. If you want the output in a different form, like single key: value pair per line, and if you are using latest inxi, I think 3.1.03 or later, you can use the -y1 flag to trigger that. If -y1 returns an error, the inxi isn't new enough.

    -a implies -xxx so your command would look like this:

    inxi --tty -y80 -c0 --no-host -Faz
    

    With latest inxi, this is shortened because -y defaults to 80 when no other value follows it, so it can be:

    inxi --tty -c0 --no-host -Fazy
    

    The width of -y is in standard mode 80 to anything you want, depends on how you like the data to show in whatever format you are wanting to output to.

    Note that inxi also has json and xml output option if that's relevant, but those are a bit harder to work with for most people than just configuring the output widths.

    If you (or someone else reading this in the future) are using the old 2.x.xx type inxi that is still stuck in various distro frozen pools, that's a handicap, because it did not handle any of this scenario very well, though it did have the super basic -y controls, but they didn't work very well. It also does not have the --tty option, nor does it have good width output controls.

    Note that as of 3.0, inxi generally determines that its output is being redirected, and turns color codes off automatically, but that doesn't always happen, particularly not in the scenario you have, where inxi is being run directly by something else, like Chef for instance, using -c0 never hurts since it's an absolute override. But in most cases (except when its being run directly by the program calling it, not via a shell or other such method) inxi will now detect that it should remove the color codes, unless forced to leave them there with -c [non zero number].