Skip to content

Plommonsorbet/tablex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tablex

Generate structured table from unstructured text based on named regex capture groups.

Description

Tablex aims to allow the regex ninja to quickly give structure to unformatted data, either to display it or to continue processing with another tool such as xsv.

Installation

cargo build --release

Usage

Use file as input:

$ tablex "alias\s+(?P<alias>[^=]+)=['\"](?P<command>.*)['\"]$" -f ~/.zshrc

Use stdin as input:

$ cat ~/.zshrc |  tablex "alias\s+(?P<alias>[^=]+)=['\"](?P<command>.*)['\"]$"

Example: init.vim

A more advanced example of parsing the neovim configuration file.

$ tablex '^\s*(?P<mode>imap|inoremap|nmap|nnoremap|map|noremap|tnoremap|tmap|vmap|vnoremap|xmap|xnoremap)(\s+<silent>\s+|\s+<expr>\s+|\s+)(?P<keys>\S+)\s+(?P<action>.*)' -f ~/.config/nvim/init.vim 
+----------+------------------------+----------------------------------------------------------------+
| mode     | keys                   | action                                                         |
+==========+========================+================================================================+
| imap     | <C-l>                  | <Plug>(coc-snippets-expand)                                    |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | Q                      | <Nop>                                                          |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>G              | :Tig<CR>                                                       |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>m              | :MagitOnly<CR>                                                 |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gs             | :Gstatus<CR>                                                   |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>ge             | :Gedit<CR>                                                     |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gp             | :Gpull nnoremap <silent> <leader>gu :Gpush                     |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gf             | :Gfetch                                                        |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gs             | :Gstatus<CR>                                                   |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gc             | :Gcommit<CR>                                                   |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>ga             | :Gcommit --amend<CR>                                           |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gl             | :Glog<CR>                                                      |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gm             | :Gmove<space>                                                  |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | <leader>gd             | :Gdelete<space>                                                |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | :                      | q:                                                             |
+----------+------------------------+----------------------------------------------------------------+
| nnoremap | ?                      | q?i                                                            |
+----------+------------------------+----------------------------------------------------------------+

Example: /etc/passwd

Create a simple more readable table from the /etc/passwd file.

$ tablex '(?P<user>[^:]+):[a-zA-z]:(?P<uid>[^:]+):(?P<gid>[^:]+):(?P<info>[^:]+):(?P<home>[^:])(?P<shell>[^:]+)' -f /etc/passwd 
+------------+-------+-------+--------------------------------------+------+-----------+
| user       | uid   | gid   | info                                 | home | shell     |
+============+=======+=======+======================================+======+===========+
| root       | 0     | 0     | System administrator                 | /    | root      |
+------------+-------+-------+--------------------------------------+------+-----------+
| messagebus | 4     | 4     | D-Bus system message bus daemon user | /    | run/dbus  |
+------------+-------+-------+--------------------------------------+------+-----------+
| polkituser | 28    | 65534 | PolKit daemon                        | /    | var/empty |
+------------+-------+-------+--------------------------------------+------+-----------+
| sshd       | 998   | 65534 | SSH privilege separation user        | /    | var/empty |
+------------+-------+-------+--------------------------------------+------+-----------+
| kasi       | 1000  | 65534 | Cool cool cool...                    | /    | home/kasi |
+------------+-------+-------+--------------------------------------+------+-----------+
| nobody     | 65534 | 65534 | Unprivileged account (don't use!)    | /    | var/empty |
+------------+-------+-------+--------------------------------------+------+-----------+

Roadmap

Testing

More installation methods.

Get some preliminary benchmarks.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published