Skip to content

'from-ssv' skips empty elements and shifts the remaining columns to the left #1350

Closed

Description

@yvrhdn

Describe the bug
If a space-separated table has an empty element (i.e. there is a row that has no value for some column), from-ssv will not detect this and shift all the next element to the left.

To Reproduce
Run some command that has space-separated table with an empty element.

In the following example the PORTS column is empty for the first element. Because of this, the value of the next column (NAMES) is shifted to the left and from-ssv splits the data into 2 tables.

❯ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a41566c3765f        docsrs_web          "/opt/docsrs/entrypo…"   2 minutes ago       Up 2 minutes                            docsrs_web_run_1ab629ca8b57
c009496a92d6        postgres:alpine     "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes        5432/tcp            docsrs_db_1

❯ docker ps | from-ssv
───┬──────────────┬────────────┬────────────────────────┬───────────────┬──────────────┬─────────────────────────────
 # │ CONTAINER ID │ IMAGE      │ COMMAND                │ CREATED       │ STATUS       │ PORTS 
───┼──────────────┼────────────┼────────────────────────┼───────────────┼──────────────┼─────────────────────────────
 0 │ a41566c3765f │ docsrs_web │ "/opt/docsrs/entrypo…" │ 2 minutes ago │ Up 2 minutes │ docsrs_web_run_1ab629ca8b57 
───┴──────────────┴────────────┴────────────────────────┴───────────────┴──────────────┴─────────────────────────────
───┬──────────────┬─────────────────┬────────────────────────┬───────────────┬──────────────┬──────────┬─────────────
 # │ CONTAINER ID │ IMAGE           │ COMMAND                │ CREATED       │ STATUS       │ PORTS    │ NAMES 
───┼──────────────┼─────────────────┼────────────────────────┼───────────────┼──────────────┼──────────┼─────────────
 1 │ c009496a92d6 │ postgres:alpine │ "docker-entrypoint.s…" │ 3 minutes ago │ Up 3 minutes │ 5432/tcp │ docsrs_db_1 
───┴──────────────┴─────────────────┴────────────────────────┴───────────────┴──────────────┴──────────┴─────────────

Expected behavior
I would expect from-ssv to detect if a column is empty and display the table correctly.

❯ docker ps | from-ssv
───┬──────────────┬─────────────────┬────────────────────────┬───────────────┬──────────────┬──────────┬────────────────────────────
 # │ CONTAINER ID │ IMAGE           │ COMMAND                │ CREATED       │ STATUS       │ PORTS    | NAMES
───┼──────────────┼─────────────────┼────────────────────────┼───────────────┼──────────────┼──────────┼────────────────────────────
 0 │ a41566c3765f │ docsrs_web      │ "/opt/docsrs/entrypo…" │ 2 minutes ago │ Up 2 minutes │          | docsrs_web_run_1ab629ca8b57 
 1 │ c009496a92d6 │ postgres:alpine │ "docker-entrypoint.s…" │ 3 minutes ago │ Up 3 minutes │ 5432/tcp │ docsrs_db_1 
───┴──────────────┴─────────────────┴────────────────────────┴───────────────┴──────────────┴──────────┴────────────────────────────

Screenshots
N/A

Configuration (please complete the following information):
Nu 0.9.0

Activity

  1. added
    category:bug
    category:enhancement
    polish
    and removed
    category:enhancement
    on Feb 6, 2020
  2. thegedge commented on Feb 15, 2020

    @thegedge
    Contributor

    I think this is working as expected. If you use --aligned-columns you'll get the expected result. What do you think, @kvrhdn ?

  3. yvrhdn commented on Feb 16, 2020

    @yvrhdn
    Author

    Using --aligned-colums fixes this indeed! Note to myself: check the help page a bit more 😅

    But it's not clear to me why this isn't the default behaviour? In which cases would you not want to parse using aligned columns?

  4. thegedge commented on Feb 16, 2020

    @thegedge
    Contributor

    But it's not clear to me why this isn't the default behaviour? In which cases would you not want to parse using aligned columns?

    I'm not 100% sure why it wasn't chosen as the default, but my guess would be that there's a cost to aligned columns, so whoever created this command would like for the user to explicitly request that, or perhaps there are examples of commands that don't align the columns (I can't think of any right now), or maybe a bit of both.

    Either way, we're really hoping to get aliases in soon, so if you wanted aligned columns to be the default, it should be easy to set up an alias that makes it do so 🎉 (I've done this for a lot of commands in my zsh profile)

  5. ilius commented on Feb 7, 2021

    @ilius
    Contributor

    I started defining functions in config.toml in startup section.
    https://github.com/nushell/nushell/blob/main/docs/sample_config/config.toml

    Once you get used to them, you will have much more power!

    Aliases are very limited, for example you can't use pipe, unlike Bash.
    But even in Bash, functions are recommended over aliases (except maybe for very simple cases).

  6. github-actions commented on Jun 24, 2021

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  7. github-actions commented on Jul 7, 2021

    @github-actions

    This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bugpolish

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions