Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wara committed May 21, 2015
1 parent 09534f6 commit 5d8056c
Showing 1 changed file with 113 additions and 54 deletions.
167 changes: 113 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ It's inspired by [h1mesuke/vim-alignta](https://github.com/h1mesuke/vim-alignta)

$ cat user.conf
[user]
name=Tom
age=17
userid=10010
name= Tom
age =17
userid = 10001

$ cat user.conf | alita -d==
[user]
name = Tom
age = 17
userid = 10010

userid = 10001

Usage
------
Expand All @@ -33,17 +32,12 @@ Usage
-h, --help show this help message
--version print the version


Installation
--------
`alita` can be easily installed as an executable.
Download the latest
[compiled binaries](https://github.com/kusabashira/alita/releases)
and put it anywhere in your executable path.

Or, if you've done Go development before
and your $GOPATH/bin directory is already in your PATH:
###compiled binary
See [releases](https://github.com/kusabashira/alita/releases)

###go get
go get github.com/kusabashira/alita

Command Line Options
Expand All @@ -61,85 +55,150 @@ Enable delimit line with regexp.
Delimit line by DELIM.
Default DELIM is `spaces (/\s+/)`.

$ cat nums.txt
1 100 10000
100 10000 1
10000 1 100

$ cat nums.txt | alita
1 100 10000
100 10000 1
10000 1 100

DELIM will interpreted as fixed string.

$ alita --delimiter==
delimit line with '='
$ cat user
name=Tom
age=17

$ alita --delimiter="->"
delimit line with '->'
$ cat user | alita -d==
(delimit line with '=')
name = Tom
age = 17

$ cat snip.cpp
cout << "9 * 2 = "<<9 * 2 << endl;
cout << "9 / 2 = "<<9 / 2 << ".." << 9 % 2<< endl;

$ alita -d="<<"
(delimit line with '<<')
cout << "9 * 2 = " << 9 * 2 << endl;
cout << "9 / 2 = " << 9 / 2 << ".." << 9 % 2 << endl;

If you enabled regexp with `-r` or `--regexp`.
DELIM will interpreted as regexp.

$ alita --regexp --delimiter="=+>"
delimit line with /=+>/
$ cat root
a=>b ===> c
c ==> d ==>e
f===> g => h

$ cat root | alita -r -d="=+>"
(delimit line with /=+>/)
a => b ===> c
c ==> d ==> e
f ===> g => h

$ alita --regexp --delimiter="[:/]+"
delimit line with /[:\/]+/
$ cat url
https://github.com/vim-scripts/Align
https://github.com/h1mesuke/vim-alignta
https://github.com/kusabashira/alita

$ cat url | alita -r -d="[:/]+"
(delimit line with /[:\/]+/)
https :// github.com / vim-scripts / Align
https :// github.com / h1mesuke / vim-alignta
https :// github.com / kusabashira / alita

###-m, --margin=FORMAT
Join cells with margin which described in FORMAT.
Default FORMAT is `1:1`.

FORMAT is `colon separated digits` or `digit only`.
FORMAT needs to be `{left-margin}:{right-margin}` or `{margin}`.

If FORMAT is `colon separated digits`,
left side will interpreted as `left-margin`
right side will interpreted as `right-margin`
If FORMAT is colon separated digits.
left side will interpreted as `left-margin`,
right side will interpreted as `right-margin`.

$ alita --margin=0:1
left-margin will 0 space
left-margin will 1 space
$ cat user | alita -d== -m=0:1
(left-margin: 0, right-margin: 1)
name= Tom
age = 17

$ alita --margin=3:2
left-margin will 3 space
left-margin will 2 space
$ cat user | alita -d== -m=3:2
(left-margin: 3, right-margin: 2)
name = Tom
age = 17

If FORMAT is `digit only`,
digit will interpreted as both `left-margin` and `right-margin`

$ alita --margin=2
left-margin will 2 space
left-margin will 2 space
$ cat user | alita --margin=2
(left-margin: 2, right-margin: 2)
name = Tom
age = 17

$ alita --margin=0
left-margin will 0 space
left-margin will 0 space
$ cat user | alita --margin=0
(left-margin will 0 space)
name=Tom
age =17

### -j, --justfy=SEQUENCE
Justfy cells by format which described in SEQUENCE.

SEQUENCE include `l`, `r` or `c`.

| char | justfy |
|:-----|:---------------|
| l | left-justfy |
| r | right-justfy |
| c | center-justfy |
| char | justfy |
|:-----|:--------------|
| l | left-justfy |
| r | right-justfy |
| c | center-justfy |

SEQUENCE will interpreted as following format.

(Default SEQUENCE is `l`)

`{L-fld-align} [ {M-fld-align} {R-fld-align} ]...`

You can specify any number of `{M-fld-align}` and `{R-fld-align}`.

If the match there is more than one,
they will continue to be applied to the order .
they will continue to be applied to the order.
(next of last `R-fld-align` is first `M-fld-align`)

$ alita --justfy=r
all cells right-justified

$ alita --justfy=lc
Only the first cell right-justified,
the rest of the cell center-justified.

$ alita --justfy=rlc
cell[0] right-justified. cell[1] left-justified.
cell[2] center-justified. cell[3] left-justified.
cell[4] center-justified. ...
$ cat text
a = bbbbb = c = ddddd = e = fffff = 1
aaa = bbb = ccc = ddd = eee = fff = 10
aaaaa = b = ccccc = d = eeeee = f = 100

$ cat text | alita -d==
(all cells left-justified)
a = bbbbb = c = ddddd = e = fffff = 1
aaa = bbb = ccc = ddd = eee = fff = 10
aaaaa = b = ccccc = d = eeeee = f = 100

$ cat text | alita -d== -j=r
(all cells right-justified)
a = bbbbb = c = ddddd = e = fffff = 1
aaa = bbb = ccc = ddd = eee = fff = 10
aaaaa = b = ccccc = d = eeeee = f = 100

$ cat text | alita -d== -j=rl
(Only the first cell right-justified,
the rest of the cell left-justified)
a = bbbbb = c = ddddd = e = fffff = 1
aaa = bbb = ccc = ddd = eee = fff = 10
aaaaa = b = ccccc = d = eeeee = f = 100

$ alita --justfy=rllcc
(cell[0] right-justified. cell[1] left-justified.
cell[2] left-justified. cell[3] center-justified.
cell[4] center-justified. cell[5] left-justified.
cell[6] left-justified. cell[7] center-justified.
cell[8] center-justified. ...)
a = bbbbb = c = ddddd = e = fffff = 1
aaa = bbb = ccc = ddd = eee = fff = 10
aaaaa = b = ccccc = d = eeeee = f = 100

License
--------
Expand Down

0 comments on commit 5d8056c

Please sign in to comment.