Skip to content

Shorten path for CWD column when displaying #462

@BenBE

Description

@BenBE

As the CWD column is usually shorter than the paths it needs to display it would be nice to shorten the displayed path such that more relevant parts are kept visible.

Full:     /var/lib/postgresql/12/main
Current:  /var/lib/postgresql/12/ma
Proposed: /var/lib/postgre~/12/main

The general algorithm could be something linke this:

  1. If string fits into target width, keep as is. Terminate this algorithm as soon as the resulting string fits.

  2. Shorten from back of last, non-terminal path component until only one unshortened character remains (skip two-char components):

    /var/lib/postgres~/12/main
    /var/lib/postgre~/12/main
    /var/lib/postgr~/12/main
    /var/lib/postg~/12/main
    /var/lib/post~/12/main
    /var/lib/pos~/12/main
    /var/lib/po~/12/main
    /var/lib/p~/12/main
    
  3. Repeat process with all path components before this.

    /var/lib64/p~/12/main
    /var/lib~/p~/12/main
    /var/li~/p~/12/main
    /var/l~/p~/12/main
    /v~/l~/p~/12/main
    
  4. combine multiple (shortened) path components

    /v~/l~/p~~/main
    /v~/l~~/main
    /v~~/main
    
  5. Shorten the last label from the middle, prioritizing to keep the front (keeping at least first+last char)

    /v~~/m~n
    

If the length that can be gained from shortening the last label exceeds what can be gained from step 3 than step 4 is prioritized.

The overall concept can likely also be reused for the CGROUP column (cf. #217).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions