~strahinja/strahinja.srht.site

ref: a1bdc8f28beb6be015c9d41f1d86de79597f0a5c strahinja.srht.site/table/index.gmi -rw-r--r-- 4.1 KiB
a1bdc8f2Страхиња Радић Added .q/.a > ul formatting 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
```

 ,==============================================. 
||       __  |         __|    __     |          ||
||      /  |_|_,______|  |___|  |____|__        ||
||______|     /       |      \  |       \_______||
||      |  --/   --   |   --  | |   -- _/       ||
||      \____/\_____/_|______/___\____\         ||
||           |           |           |          ||
``==============================================" 

```

# table

Command line utility to format and display CSV.


## Prerequisites

C compiler, preferably GNU C or similar.


## Install

```
$ git clone https://git.sr.ht/~strahinja/table
$ cd table
$ su
```

Then, if you have 

=> https://github.com/apenwarr/redo apenwarr/redo

```
# redo install
```

if you don't:

```
# ./do install
```


## Examples

Periodically display CPU load information in a single-line table

```
$ watch "table /proc/loadavg -d ' ' -c 50 -n -s ss"
```

Format a long list of files in the current directory in a double line table with single-line column divisors

```
$ LC_ALL=C ls -l | tail -n +2 | sed -e 's/ \+/ /g' | table -d ' ' -n
```

Like the above, but only permissions and file names are printed in a narrow table

```
$ LC_ALL=C ls -l | tail -n +2 | awk '{ print $1 " " $9 }' | table -d ' ' -c 30 -n
```


## Configuring GNU Midnight Commander (mc)

=> https://www.midnight-commander.org   GNU Midnight Commander file manager 

can be configured to use table as a viewer (F3) for CSV files. To do that, edit /usr/lib/mc/ext.d/text.sh (or make and edit a local copy, for example in ~/bin/text.sh, which we will assume here) so that

```
case "${filetype}" in
```

block in do_view_action() function includes:

```
    csv)
        table -m -n "${MC_EXT_FILENAME}"
        ;;
```

You also need to edit extension file (Command->Edit extension file) or just edit ~/.config/mc/mc.ext and add the lines:

```
shell/.csv
        View=%view{ascii} ~/bin/text.sh view csv %var{PAGER:more}
```

before includes and default target.


## Configuring ranger file manager

=> https://github.com/ranger/ranger ranger file manager


can be configured to use table as a CSV file viewer. To do that, add the following to ~/.config/ranger/scope.sh, within the function handle_extension():

```
## CSV
csv)
    table -m "${FILE_PATH}" && exit 5
    exit 1;;</pre>
```


## Configuring vifm

=> https://vifm.info    vifm file manager 

can also be configured to use table as a CSV file viewer. To accomplish this, add the following lines to ~/.config/vifm/vifmrc:

```
" CSV
fileviewer *.csv
	\ table -m %c
```


## Changelog


### v0.3

* Removed libunistring as a dependency


### v0.2.2

* Optimizations and bugfixes
* Added description how to configure table as a viewer for GNU MC
* Added the --msdos option
* Changed URLs to sourcehut


### v0.2.1

* Added format support


### v0.2

* Switched to apenwarr/redo
* Core code rewrite. Prevented leaks with valgrind
* New examples directory, updated scripts in tests
* Updated manpage


### v0.1.2-beta

* Add --border-mode
* Fix last row in ls -mw30 | table when last input line has only one column


### v0.1.1-beta

* Ignore malformed UTF-8 sequences. Segmentation faulted (test/who-Huw.sh with LC_ALL=sr_RS.UTF8 and cyrillic user names)
* Use "T" connector chars; connector selection similar to -s


### v0.1-alpha

* Read and display columns
* Handle tabs - unwrap to spaces at tab stops (test/lsb_release.sh)
* Better UTF-8 substring code based on screen columns


## License

table - Command line utility to format and display CSV.
Copyright (C) 2020, 2021 Страхиња Радић

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see 

=> https://www.gnu.org/licenses/