├── .gitignore
├── refs
├── cat
├── col
├── cols
├── drop
├── file
├── fs
├── log
├── map
├── mark
├── max
├── min
├── row
├── rows
├── show
├── sum
├── take
├── trim
├── turn
├── uniq
├── after
├── before
├── concat
├── count
├── filter
├── length
├── lower
├── nixar
├── order
├── remove
├── split
├── substr
├── table
├── unique
├── upper
├── clipboard
├── content
├── exclude
├── replace
└── reverse
├── README.sh
├── docs
├── nixar.js
├── max.js
├── sum.js
├── min.js
├── after.js
├── count.js
├── trim.js
├── substr.js
├── remove.js
├── turn.js
├── order.js
├── reverse.js
├── before.js
├── lower.js
├── upper.js
├── exclude.js
├── replace.js
├── map.js
├── unique.js
├── split.js
├── take.js
├── rows.js
├── length .js
├── log.js
├── concat.js
├── table .js
├── drop.js
├── cols.js
└── fs.js
├── commands
├── show.ls
├── count.ls
├── length.ls
├── sum.ls
├── remove.ls
├── take.ls
├── lower.ls
├── reverse.ls
├── unique.ls
├── upper.ls
├── concat.ls
├── content.ls
├── min.ls
├── split.ls
├── max.ls
├── replace.ls
├── map.ls
├── rows.ls
├── drop.ls
├── log.ls
├── before.ls
├── exclude.ls
├── filter.ls
├── substr.ls
├── mark.ls
├── trim.ls
├── table.ls
├── after.ls
├── nixar.ls
├── cols.ls
├── fs.ls
├── turn.ls
└── order.ls
├── compiled-commands
├── show.js
├── content.js
├── length.js
├── take.js
├── remove.js
├── sum.js
├── unique.js
├── split.js
├── concat.js
├── reverse.js
├── lower.js
├── upper.js
├── max.js
├── min.js
├── count.js
├── replace.js
├── rows.js
├── map.js
├── before.js
├── log.js
├── substr.js
├── exclude.js
├── trim.js
├── mark.js
├── drop.js
├── filter.js
├── after.js
├── table.js
├── nixar.js
├── cols.js
├── turn.js
├── fs.js
└── order.js
├── README.ls
├── generate.ls
├── generate.js
├── README.md
├── package.json
├── nixar.ls
└── nixar.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log
3 | run
4 | nixardoc.*
5 |
--------------------------------------------------------------------------------
/refs/cat:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('cat')
--------------------------------------------------------------------------------
/refs/col:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('col')
--------------------------------------------------------------------------------
/refs/cols:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('cols')
--------------------------------------------------------------------------------
/refs/drop:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('drop')
--------------------------------------------------------------------------------
/refs/file:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('file')
--------------------------------------------------------------------------------
/refs/fs:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('fs')
--------------------------------------------------------------------------------
/refs/log:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('log')
--------------------------------------------------------------------------------
/refs/map:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('map')
--------------------------------------------------------------------------------
/refs/mark:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('mark')
--------------------------------------------------------------------------------
/refs/max:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('max')
--------------------------------------------------------------------------------
/refs/min:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('min')
--------------------------------------------------------------------------------
/refs/row:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('row')
--------------------------------------------------------------------------------
/refs/rows:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('rows')
--------------------------------------------------------------------------------
/refs/show:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('show')
--------------------------------------------------------------------------------
/refs/sum:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('sum')
--------------------------------------------------------------------------------
/refs/take:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('take')
--------------------------------------------------------------------------------
/refs/trim:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('trim')
--------------------------------------------------------------------------------
/refs/turn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('turn')
--------------------------------------------------------------------------------
/refs/uniq:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('uniq')
--------------------------------------------------------------------------------
/refs/after:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('after')
--------------------------------------------------------------------------------
/refs/before:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('before')
--------------------------------------------------------------------------------
/refs/concat:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('concat')
--------------------------------------------------------------------------------
/refs/count:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('count')
--------------------------------------------------------------------------------
/refs/filter:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('filter')
--------------------------------------------------------------------------------
/refs/length:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('length')
--------------------------------------------------------------------------------
/refs/lower:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('lower')
--------------------------------------------------------------------------------
/refs/nixar:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('nixar')
--------------------------------------------------------------------------------
/refs/order:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('order')
--------------------------------------------------------------------------------
/refs/remove:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('remove')
--------------------------------------------------------------------------------
/refs/split:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('split')
--------------------------------------------------------------------------------
/refs/substr:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('substr')
--------------------------------------------------------------------------------
/refs/table:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('table')
--------------------------------------------------------------------------------
/refs/unique:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('unique')
--------------------------------------------------------------------------------
/refs/upper:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('upper')
--------------------------------------------------------------------------------
/refs/clipboard:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('clipboard')
--------------------------------------------------------------------------------
/refs/content:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('content')
--------------------------------------------------------------------------------
/refs/exclude:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('exclude')
--------------------------------------------------------------------------------
/refs/replace:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('replace')
--------------------------------------------------------------------------------
/refs/reverse:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | require('../nixar.js')('reverse')
--------------------------------------------------------------------------------
/README.sh:
--------------------------------------------------------------------------------
1 | #nixardoc
2 | lsc -c *.ls
3 | rm -rf compiled-commands
4 | lsc -c commands/*.ls -o compiled-commands
5 | lsc -c README.ls
6 | node README.js
7 | rm README.js
8 |
9 |
--------------------------------------------------------------------------------
/docs/nixar.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "nixar",
4 | "files": [
5 | "
Print a list of commands nixar
\n\nCommand\nsh\n$ nixar #=> prints all available commands\n
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/docs/max.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "max",
4 | "files": [
5 | "It displays the maximum value
\n\nInput\nsh\n1\n2\n3\n4\n5\n
\n\nCommand\nsh\n$ show line.css | max
\n
\n\nOutput\nsh\n5\n
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/docs/sum.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "sum",
4 | "files": [
5 | "It displays the total value of
\n\nInput\nsh\n1\n2\n3\n4\n5\n
\n\nCommand\nsh\n$ show line.css | sum
\n
\n\nOutput\nsh\n012345\n
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/commands/show.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, cat)->
2 | repo.commands.push do
3 | name: "show"
4 | desc: "Prints file, file lines, file created date, file modified date"
5 | input: \nothing
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: cat.compile
--------------------------------------------------------------------------------
/commands/count.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "count"
4 | desc: "Calculates lines count"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | lines |> (.length)
--------------------------------------------------------------------------------
/commands/length.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "length"
4 | desc: "Calculates characters count"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | input.length
--------------------------------------------------------------------------------
/commands/sum.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "sum"
4 | desc: "Calc sum of numbers in list"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | input |> p.sum
--------------------------------------------------------------------------------
/commands/remove.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "remove"
4 | desc: "Removes substring in line"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | input.split(mask).join("")
--------------------------------------------------------------------------------
/commands/take.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "take"
4 | desc: "Select lines"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | lines |> p.take mask
15 |
--------------------------------------------------------------------------------
/commands/lower.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "lower"
4 | desc: "Converts characters to lowercase"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | (input ? "").to-lower-case!
--------------------------------------------------------------------------------
/commands/reverse.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "reverse"
4 | desc: "Reverses the order of output"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | lines |> p.reverse
--------------------------------------------------------------------------------
/commands/unique.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "unique"
4 | desc: "Get unique records"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | lines |> p.unique
15 |
--------------------------------------------------------------------------------
/commands/upper.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "upper"
4 | desc: "Convert characters to uppercase"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | (input ? "").to-upper-case!
--------------------------------------------------------------------------------
/docs/min.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "min",
4 | "files": [
5 | "It displays the number of characters of the shortest line
\n\nInput\nsh\n1\n2\n3\n4\n5\n
\n\nCommand\nsh\n$ show line.css | min
\n
\n\nOutput\nsh\n1\n
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/commands/concat.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "concat"
4 | desc: "Joins lines into one line"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | lines |> p.join mask
15 |
--------------------------------------------------------------------------------
/commands/content.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, cat)->
2 | repo.commands.push do
3 | name: "content"
4 | desc: "Prints content, content lines, content created date, content modified date, content size"
5 | input: \line
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: cat.compile
--------------------------------------------------------------------------------
/commands/min.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "min"
4 | desc: "Calculates minimum number from list of numbers"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | input |> p.minimum
--------------------------------------------------------------------------------
/commands/split.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "split"
4 | desc: "Splits line into lines"
5 | input: \line
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, line, callback)->
14 | callback line.split(mask)
15 |
--------------------------------------------------------------------------------
/commands/max.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "max"
4 | desc: "Calculates maximum number from list of numbers"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | input |> p.maximum
15 |
--------------------------------------------------------------------------------
/docs/after.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "after",
4 | "files": [
5 | "Native Command\nsh\n$ echo \"1.2.3.4.5\" | sed s/1.//g #=> \"2.3.4.5\"
\n
",
6 | "Print the string after a substring
\n\nCommand\nsh\n$ echo \"1.2.3.4.5\" | after \".\" #=> \"2.3.4.5\"\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/replace.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "replace"
4 | desc: "Replaces substring in line"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | keys = mask.split(\,)
15 | input.split(keys.0).join(keys.1)
--------------------------------------------------------------------------------
/docs/count.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "count",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename | wc -l #=> 5\n
",
6 | "Calculate the number of lines
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename | count #=> 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/map.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "map"
4 | desc: "Transforms line"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | if (mask ? "") is ""
15 | return input
16 | mask.split(\*).map(-> it.yellow).join(input)
--------------------------------------------------------------------------------
/commands/rows.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p, parser)->
2 | repo.commands.push do
3 | name: \rows
4 | desc: "Gets specific rows"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | rows = parser.numbers mask, (lines.length - 1)
15 | lines.filter( (_, i) -> rows.index-of(i) > -1 )
--------------------------------------------------------------------------------
/docs/trim.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "trim",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | cut -c2-3
\n
",
6 | "Trim the string
\n\nInput\nsh\ntest\ntest\ntest\ntest\ntest\n
\n\nCommand\nsh\n$ cat filename.txt | trim t\n
\n\nOutput\nsh\nes\nes\nes\nes\nes\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/drop.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: \drop
4 | desc: "Drops lines"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | compile: ->
9 | (mask, lines)->
10 | count = mask.match('[0-9]+')?0 ? 1
11 | if mask.index-of('last') > -1
12 | lines |> p.reverse |> p.drop count |> p.reverse
13 | else
14 | lines |> p.drop count
15 |
--------------------------------------------------------------------------------
/docs/substr.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "substr",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | cut -c 6-
\n
",
6 | "Delete first 5 characters in each line
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | substr 5\n
\n\nOutput\nsh\n1\n2\n3\n4\n5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/log.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "log"
4 | desc: "Logs output to file and continues printing"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | fs = require \fs
14 | (mask, input)->
15 | if (input ? "") isnt ""
16 | fs.append-file-sync mask, (input + "\r\n"), \utf-8
17 | input
--------------------------------------------------------------------------------
/compiled-commands/show.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, cat){
4 | return repo.commands.push({
5 | name: "show",
6 | desc: "Prints file, file lines, file created date, file modified date",
7 | input: 'nothing',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: cat.compile
14 | });
15 | };
16 | }).call(this);
17 |
--------------------------------------------------------------------------------
/docs/remove.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "remove",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed -e 's/line //g'\n
",
6 | "Remove the substring from string
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | remove \"line \"\n
\n\nOutput\nsh\n1\n2\n3\n4\n5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/turn.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "turn",
4 | "files": [
5 | "Row to column, column to row transformation. This command does job of concat and split commands
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | turn
\n
\n\nOutput\nsh\nline line line line line\n1 2 3 4 5\n
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/commands/before.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "before"
4 | desc: "Prints everything before mask"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | index =
15 | input.index-of(mask)
16 | if index > -1
17 | input.substr(0, index)
18 | else
19 | input
--------------------------------------------------------------------------------
/docs/order.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "order",
4 | "files": [
5 | "Native Command\nsh\ncat filename.txt | sort -k 1,3n\n
",
6 | "Display rows in ascending order
\n\nInput
\n\nsh\nline 2\nline 3\nline 1\nline 5\nline 4\n
\n\nCommand\nsh\ncat filename.txt | order 1\n
\n\nOutput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/reverse.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "reverse",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed '1!G;h;$!d'\n
",
6 | "Display the list in reverse order
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | reverse\n
\n\nOutput\nsh\nline 5\nline 4\nline 3\nline 2\nline 1\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/before.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "before",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed 's/^\\(.*\\).$/\\1 /'\n
",
6 | "Print the string before a substring
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | before \" \"\n
\n\nOutput\nsh\nline\nline\nline\nline\nline\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/lower.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "lower",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | tr '[:upper:]' '[:lower:]' #=> line 1 line 2 line 3 line 4 line 5\n
",
6 | "Display text in lowercase
\n\nInput\nsh\nLINE 1 LINE 2 LINE 3 LINE 4 LINE 5\n
\n\nCommand\nsh\n$ cat filename.txt | lower #=> line 1 line 2 line 3 line 4 line 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/upper.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "upper",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | tr '[:lower:]' '[:upper:]' #=> LINE 1 LINE 2 LINE 3 LINE 4 LINE 5\n
",
6 | "Display the text in UPPERCASE
\n\nInput\nsh\nline 1 line 2 line 3 line 4 line 5\n
\n\nOutput\nsh\n$ cat filename.txt | upper #=> LINE 1 LINE 2 LINE 3 LINE 4 LINE 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/compiled-commands/content.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, cat){
4 | return repo.commands.push({
5 | name: "content",
6 | desc: "Prints content, content lines, content created date, content modified date, content size",
7 | input: 'line',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: cat.compile
14 | });
15 | };
16 | }).call(this);
17 |
--------------------------------------------------------------------------------
/docs/exclude.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "exclude",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | grep -Ev '5' \n
",
6 | "Excludeds lines by pattern. Opposite of filter command.
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | exclude 5\n
\n\nOutput\n\nline 1\nline 2\nline 3\nline 4\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/replace.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "replace",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed 's/line/word/g'\n
",
6 | "Replace the substring with another
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
\n\nCommand\nsh\n$ cat filename.txt | replace line,word\n
\n\nOutput\nsh\nword 1\nword 2\nword 3\nword 4\nword 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/exclude.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "exclude"
4 | desc: "Excludes line specified by mask"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | if (mask ? "") is ""
15 | return if (input ? "") is "" then null else input
16 | if input.match(mask)
17 | null
18 | else
19 | input
--------------------------------------------------------------------------------
/commands/filter.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "filter"
4 | desc: "Filter lines"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | if (mask ? "") is ""
15 | return if (input ? "") is "" then null else input
16 | if input.match(mask)
17 | input.split(mask).join(mask.yellow)
18 | else
19 | null
--------------------------------------------------------------------------------
/commands/substr.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "substr"
4 | desc: "Returns the part of string specified by start and length parameters"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, line)->
14 | pars = mask.split(',')
15 | if pars.length is 0
16 | line.substr pars.0
17 | else
18 | line.substr pars.0, pars.1
--------------------------------------------------------------------------------
/docs/map.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "map",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed 's/^/lines /' \n
",
6 | "Transformation of a list of files and folders in the command is executed on them
\n\nInput\nsh\n1\n2\n3\n4\n5\n
\n\nCommand\nsh\ncat filename.txt | map \"lines *\"\n
\n\nOutput\nsh\nlines 1\nlines 2\nlines 3\nlines 4\nlines 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/unique.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "unique",
4 | "files": [
5 | "Command\nsh\n$ cat filename.txt | unique -u \n
",
6 | "Remove duplicate lines from the list
\n\nInput\nsh\n1 line\n2 line\n3 line\n4 line\n5 line\n1 line\n2 line\n3 line\n4 line\n5 line\n
\n\nCommand\nsh\n$ cat filename.txt | unique\n
\n\nOutput\nsh\n1 line\n2 line\n3 line\n4 line\n5 line\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/split.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "split",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | awk 'BEGIN{RS=\", \"}{print}'\n
",
6 | "Split line into multiple lines by a tab character
\n\nInput\nsh\nline 1, line 2, line 3, line 4, line 5\n
\n\nCommand\nsh\n$ cat filename.txt | split \", \"\n
\n\nOutput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/take.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "take",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed -n '1,5p;'\n
",
6 | "Take only 5 lines and skip other
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\nline 10\n
\n\nCommand\nsh\n$ cat filename.txt | take 5\n
\n\nOutput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/docs/rows.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "rows",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed -n '1,5p;'
\n
",
6 | "Take 1 - 5 lines and skip other
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\nline 10\n
\n\nCommand\nsh\n$ cat filename.txt | rows 1-5\n
\n\nOutput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/compiled-commands/length.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "length",
6 | desc: "Calculates characters count",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return input.length;
16 | };
17 | }
18 | });
19 | };
20 | }).call(this);
21 |
--------------------------------------------------------------------------------
/compiled-commands/take.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "take",
6 | desc: "Select lines",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | return p.take(mask)(
16 | lines);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/compiled-commands/remove.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "remove",
6 | desc: "Removes substring in line",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return input.split(mask).join("");
16 | };
17 | }
18 | });
19 | };
20 | }).call(this);
21 |
--------------------------------------------------------------------------------
/compiled-commands/sum.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "sum",
6 | desc: "Calc sum of numbers in list",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return p.sum(
16 | input);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/compiled-commands/unique.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "unique",
6 | desc: "Get unique records",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | return p.unique(
16 | lines);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/commands/mark.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "mark"
4 | desc: "Highlights lines' parts according to the provided mask"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | if (mask ? "") is ""
15 | return if (input ? "") is "" then null else input
16 | if input.match(mask)
17 | input.split(mask).join(mask.green)
18 | else
19 | input
--------------------------------------------------------------------------------
/compiled-commands/split.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "split",
6 | desc: "Splits line into lines",
7 | input: 'line',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, line, callback){
15 | return callback(line.split(mask));
16 | };
17 | }
18 | });
19 | };
20 | }).call(this);
21 |
--------------------------------------------------------------------------------
/compiled-commands/concat.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "concat",
6 | desc: "Joins lines into one line",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | return p.join(mask)(
16 | lines);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/commands/trim.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "trim"
4 | desc: "Remove spaces from start and end of line. But if you provide the substring it will remove it from start and end of line"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | mask = if (mask ? "") is "" then "\\s+" else mask
15 | re = new RegExp("^#{mask}|#{mask}$","g")
16 | String(input).replace(re, '')
17 |
--------------------------------------------------------------------------------
/compiled-commands/reverse.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "reverse",
6 | desc: "Reverses the order of output",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | return p.reverse(
16 | lines);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/compiled-commands/lower.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "lower",
6 | desc: "Converts characters to lowercase",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return (input != null ? input : "").toLowerCase();
16 | };
17 | }
18 | });
19 | };
20 | }).call(this);
21 |
--------------------------------------------------------------------------------
/compiled-commands/upper.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "upper",
6 | desc: "Convert characters to uppercase",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return (input != null ? input : "").toUpperCase();
16 | };
17 | }
18 | });
19 | };
20 | }).call(this);
21 |
--------------------------------------------------------------------------------
/compiled-commands/max.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "max",
6 | desc: "Calculates maximum number from list of numbers",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return p.maximum(
16 | input);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/compiled-commands/min.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "min",
6 | desc: "Calculates minimum number from list of numbers",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | return p.minimum(
16 | input);
17 | };
18 | }
19 | });
20 | };
21 | }).call(this);
22 |
--------------------------------------------------------------------------------
/compiled-commands/count.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "count",
6 | desc: "Calculates lines count",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | return function(it){
16 | return it.length;
17 | }(
18 | lines);
19 | };
20 | }
21 | });
22 | };
23 | }).call(this);
24 |
--------------------------------------------------------------------------------
/docs/length .js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "length ",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | wc -c filename.txt #=> 72 filename.txt
\n
",
6 | "List the number of characters in the line
\n\ninput\nsh\n1 line 2 line 3 line 4 line 5 line \n1 line 2 line 3 line 4 line 5 line\n
\n\nCommand\n```sh\n$ cat filename.txt | length #=> 35\n #=> 35
\n\n$ fs all | filter filename.txt | file | concat \" \" | length #=> 72
\n```
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/compiled-commands/replace.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "replace",
6 | desc: "Replaces substring in line",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | var keys;
16 | keys = mask.split(',');
17 | return input.split(keys[0]).join(keys[1]);
18 | };
19 | }
20 | });
21 | };
22 | }).call(this);
23 |
--------------------------------------------------------------------------------
/docs/log.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "log",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed 's/1 //g' | grep -i \" \" >> filename.txt
\n
",
6 | "Log current output into file and continue piping\"
\n\nInput\nsh\n1 line 1\n1 line 2\n1 line 3\n1 line 4\n1 line 5\n
\n\nCommand\nsh\n$ cat filename.txt | remove \"1 \" | log filename.txt\n
\n\nThe yield and the contents of filename.txt file matches\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/commands/table.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "table"
4 | desc: "Create columns from line based on separator"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | Table = require \easy-table
14 | (mask, lines)->
15 | if (mask ? "") is ""
16 | return ""
17 | t = new Table
18 | lines.forEach (product)->
19 | product.split(mask)?forEach (item, i)->
20 | t.cell(i, item.replace(/[ ]/g,'_'))
21 | t.newRow!
22 | t.print!
--------------------------------------------------------------------------------
/commands/after.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: "after"
4 | desc: "Prints everything after [mask]. Has option 'after last [mask]'"
5 | input: \line
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, input)->
14 | last = mask.index-of(\last) is 0
15 | str = mask.replace(/^last /g,"")
16 | index =
17 | if last then input.last-index-of(str) else input.index-of(str)
18 | if index > -1
19 | input.substr(index + str.length)
20 | else
21 | input
--------------------------------------------------------------------------------
/compiled-commands/rows.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p, parser){
4 | return repo.commands.push({
5 | name: 'rows',
6 | desc: "Gets specific rows",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | var rows;
16 | rows = parser.numbers(mask, lines.length - 1);
17 | return lines.filter(function(_, i){
18 | return rows.indexOf(i) > -1;
19 | });
20 | };
21 | }
22 | });
23 | };
24 | }).call(this);
25 |
--------------------------------------------------------------------------------
/compiled-commands/map.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "map",
6 | desc: "Transforms line",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | if ((mask != null ? mask : "") === "") {
16 | return input;
17 | }
18 | return mask.split('*').map(function(it){
19 | return it.yellow;
20 | }).join(input);
21 | };
22 | }
23 | });
24 | };
25 | }).call(this);
26 |
--------------------------------------------------------------------------------
/compiled-commands/before.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "before",
6 | desc: "Prints everything before mask",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | var index;
16 | index = input.indexOf(mask);
17 | if (index > -1) {
18 | return input.substr(0, index);
19 | } else {
20 | return input;
21 | }
22 | };
23 | }
24 | });
25 | };
26 | }).call(this);
27 |
--------------------------------------------------------------------------------
/compiled-commands/log.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "log",
6 | desc: "Logs output to file and continues printing",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | var fs;
15 | fs = require('fs');
16 | return function(mask, input){
17 | if ((input != null ? input : "") !== "") {
18 | fs.appendFileSync(mask, input + "\r\n", 'utf-8');
19 | }
20 | return input;
21 | };
22 | }
23 | });
24 | };
25 | }).call(this);
26 |
--------------------------------------------------------------------------------
/docs/concat.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "concat",
4 | "files": [
5 | "Native Command\nsh\n$ filename.txt | sed ':a;N;$!ba;s/\\n/ /g'\n
",
6 | "Concatenation of sevaral lines into one line
\n\nInput\nsh\nafter print everything after mask\nbefore print everything before mask\ncol get specific columns\nconcat join lines into one line\ncount calculate count of lines\ndrop drop lines\n
\n\nCommand\nsh\n$ cat filename.txt | concat \" \"\n
\n\nOutput\nsh\nafter print everything after mask before print everything before mask col get specific columns concat join lines into one line count calculate count of lines drop drop lines\n
"
7 | ]
8 | });
9 | }
--------------------------------------------------------------------------------
/compiled-commands/substr.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "substr",
6 | desc: "Returns the part of string specified by start and length parameters",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, line){
15 | var pars;
16 | pars = mask.split(',');
17 | if (pars.length === 0) {
18 | return line.substr(pars[0]);
19 | } else {
20 | return line.substr(pars[0], pars[1]);
21 | }
22 | };
23 | }
24 | });
25 | };
26 | }).call(this);
27 |
--------------------------------------------------------------------------------
/compiled-commands/exclude.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "exclude",
6 | desc: "Excludes line specified by mask",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | if ((mask != null ? mask : "") === "") {
16 | return (input != null ? input : "") === "" ? null : input;
17 | }
18 | if (input.match(mask)) {
19 | return null;
20 | } else {
21 | return input;
22 | }
23 | };
24 | }
25 | });
26 | };
27 | }).call(this);
28 |
--------------------------------------------------------------------------------
/compiled-commands/trim.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "trim",
6 | desc: "Remove spaces from start and end of line. But if you provide the substring it will remove it from start and end of line",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | var re;
16 | mask = (mask != null ? mask : "") === "" ? "\\s+" : mask;
17 | re = new RegExp("^" + mask + "|" + mask + "$", "g");
18 | return String(input).replace(re, '');
19 | };
20 | }
21 | });
22 | };
23 | }).call(this);
24 |
--------------------------------------------------------------------------------
/compiled-commands/mark.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "mark",
6 | desc: "Highlights lines' parts according to the provided mask",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | if ((mask != null ? mask : "") === "") {
16 | return (input != null ? input : "") === "" ? null : input;
17 | }
18 | if (input.match(mask)) {
19 | return input.split(mask).join(mask.green);
20 | } else {
21 | return input;
22 | }
23 | };
24 | }
25 | });
26 | };
27 | }).call(this);
28 |
--------------------------------------------------------------------------------
/README.ls:
--------------------------------------------------------------------------------
1 | require \xonom
2 | .service \repo, ->
3 | commands: []
4 | docs: []
5 | .run "#{__dirname}/compiled-commands/*.js"
6 | .service \p, ->
7 | require \prelude-ls
8 | .run (repo, p)->
9 | lines = []
10 | $ = lines~push
11 | $ '# New shell commands'
12 | $ 'Joyable equivalents for existent linux commands'
13 | $ ''
14 | $ ''
15 | $ ''
16 | $ 'npm install -g nixar'
17 | $ ''
18 | $ '###Commands'
19 | $ ''
20 | repo.commands.for-each (cmd)->
21 | $ "#### #{cmd.name}"
22 | $ "#{cmd.desc}"
23 | console.log lines.join('\n')
24 | require('fs').writeFileSync('README.md', lines.join(\\n), \utf8)
--------------------------------------------------------------------------------
/compiled-commands/drop.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: 'drop',
6 | desc: "Drops lines",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | compile: function(){
11 | return function(mask, lines){
12 | var count, ref$, ref1$;
13 | count = (ref$ = (ref1$ = mask.match('[0-9]+')) != null ? ref1$[0] : void 8) != null ? ref$ : 1;
14 | if (mask.indexOf('last') > -1) {
15 | return p.reverse(
16 | p.drop(count)(
17 | p.reverse(
18 | lines)));
19 | } else {
20 | return p.drop(count)(
21 | lines);
22 | }
23 | };
24 | }
25 | });
26 | };
27 | }).call(this);
28 |
--------------------------------------------------------------------------------
/compiled-commands/filter.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "filter",
6 | desc: "Filter lines",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | if ((mask != null ? mask : "") === "") {
16 | return (input != null ? input : "") === "" ? null : input;
17 | }
18 | mask = mask.replace(/\\/g, '\\\\');
19 | if (input.match(mask)) {
20 | return input.split(mask).join(mask.yellow);
21 | } else {
22 | return null;
23 | }
24 | };
25 | }
26 | });
27 | };
28 | }).call(this);
29 |
--------------------------------------------------------------------------------
/docs/table .js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "table ",
4 | "files": [
5 | "Create a virtual table from the text
\n\nInput\nsh\nAFTER PRINT EVERYTHING AFTER MASK\nBEFORE PRINT EVERYTHING BEFORE MASK\nCOL GET SPECIFIC COLUMNS\nCONCAT JOIN LINES INTO ONE LINE\nCOUNT CALCULATE COUNT OF LINES\nDROP DROP LINES\nEXCLUDE EXCLUDE LINE BY FOUNDED MASK\n
\n\nCommand\nsh\n$ cat filename.txt | table \" \"\n
\n\nOutput\n```\nAFTER PRINT EVERYTHING AFTER MASK
\nBEFORE PRINT EVERYTHING BEFORE MASK
\nCOL GET SPECIFIC COLUMNS
\nCONCAT JOIN LINES INTO ONE LINE\nCOUNT CALCULATE COUNT OF LINES
\nDROP DROP LINES
\nEXCLUDE EXCLUDE LINE BY FOUNDED MASK
\n\n```
"
6 | ]
7 | });
8 | }
--------------------------------------------------------------------------------
/compiled-commands/after.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "after",
6 | desc: "Prints everything after [mask]. Has option 'after last [mask]'",
7 | input: 'line',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, input){
15 | var last, str, index;
16 | last = mask.indexOf('last') === 0;
17 | str = mask.replace(/^last /g, "");
18 | index = last
19 | ? input.lastIndexOf(str)
20 | : input.indexOf(str);
21 | if (index > -1) {
22 | return input.substr(index + str.length);
23 | } else {
24 | return input;
25 | }
26 | };
27 | }
28 | });
29 | };
30 | }).call(this);
31 |
--------------------------------------------------------------------------------
/commands/nixar.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "nixar"
4 | desc: "Shows all commands. Run `nixar killall` in order to kill all running nixar's commands"
5 | input: \nothing
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (skip, mask, callback)->
14 | switch (mask ? "")
15 | case ""
16 | transform = (c)->
17 | "#{c.name} ".green + c.desc
18 | callback repo.commands.map(transform)
19 | case "killall"
20 | cmd = "killall -9 " + repo.commands.map(-> it.name).join(" ")
21 | exec = require('child_process').exec
22 | exec cmd, (error, stdout, stderr)->
23 | callback ["killed"]
24 | else
25 | callback repo.commands.filter(-> it.name is mask).map(JSON.stringify)
26 |
--------------------------------------------------------------------------------
/docs/drop.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "drop",
4 | "files": [
5 | "Native Command\nsh\n$ cat filename.txt | sed '1, 5d'
\n
",
6 | "Delete first 5 lines from the list
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9 \nline 10\n
\n\nCommand\nsh\n$ cat filename.txt | drop 5\n
\n\nOutput\nsh\nline 6\nline 7\nline 8\nline 9 \nline 10\n
",
7 | "Command\nsh\n$ cat filename.txt | sed -n -e :a -e '6,10!{P;N;D;};N;ba' \n
",
8 | "Delete last 5 lines from the list
\n\nInput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9 \nline 10\n
\n\nCommand\nsh\n$ cat filename.txt | reverse | drop 5 | reverse\n
\n\nOutput\nsh\nline 1\nline 2\nline 3\nline 4\nline 5\n
"
9 | ]
10 | });
11 | }
--------------------------------------------------------------------------------
/generate.ls:
--------------------------------------------------------------------------------
1 | fs = require \fs
2 | glob = require \glob
3 | p = require \prelude-ls
4 | is-file= (name)->
5 | fs.exists-sync(name) and fs.lstat-sync(name).is-file!
6 |
7 | update-json = (path, update)->
8 | file = if is-file(path) then require(path) else {}
9 | save = ->
10 | fs.write-file-sync(path, json, \utf8)
11 | update file, save
12 | json = JSON.stringify(file, null, 4)
13 | save!
14 |
15 | files = glob.sync \compiled-commands/*
16 |
17 | update-json do
18 | * \./package.json
19 | * (model)->
20 | name = (filename)->
21 | filename.match("([a-z]+).[^.]+$").1
22 | ref = ->
23 | "./refs/#it"
24 | names =
25 | files |> p.map name
26 | names.for-each (it)->
27 | fs.write-file-sync do
28 | *ref it
29 | * "#!/usr/bin/env node\nrequire('../nixar.js')('#it')"
30 | * \utf8
31 | model.bin =
32 | names |> p.map (-> [it, ref it])
33 | |> p.pairs-to-obj
--------------------------------------------------------------------------------
/commands/cols.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p, parser)->
2 | repo.commands.push do
3 | name: \cols
4 | desc: "Get specific columns. Example: `cols 1-3 5 6 9-20`"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | (mask, lines)->
14 | pad = (str, len) ->
15 | ((if str is '' then ' ' else str) + Array(len).join(' ')).slice 0, len
16 | state =
17 | maxes: []
18 | columns: []
19 | each-item = (s)->
20 | s.for-each (_, i)->
21 | state.maxes[i] = Math.max(s[i].length, state.maxes[i] ? 0)
22 | make-columns = (it)->
23 | state.columns = parser.numbers mask, (state.maxes.length - 1)
24 | it
25 | lines |> p.map (.split(/[ ]+/))
26 | |> p.each each-item
27 | |> make-columns
28 | |> p.map (.map((item, c)-> pad(item, state.maxes[c])).filter( (item, i)-> state.columns.index-of(i) > -1).join (' '))
29 |
--------------------------------------------------------------------------------
/compiled-commands/table.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: "table",
6 | desc: "Create columns from line based on separator",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | var Table;
15 | Table = require('easy-table');
16 | return function(mask, lines){
17 | var t;
18 | if ((mask != null ? mask : "") === "") {
19 | return "";
20 | }
21 | t = new Table;
22 | lines.forEach(function(product){
23 | var ref$;
24 | if ((ref$ = product.split(mask)) != null) {
25 | ref$.forEach(function(item, i){
26 | return t.cell(i, item.replace(/[ ]/g, '_'));
27 | });
28 | }
29 | return t.newRow();
30 | });
31 | return t.print();
32 | };
33 | }
34 | });
35 | };
36 | }).call(this);
37 |
--------------------------------------------------------------------------------
/commands/fs.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "fs"
4 | desc: "Finds file(s) by glob-like mask (*.* or **/*.* or */ or all)"
5 | input: \nothing
6 | output: \lines
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | glob = require \glob-all
14 | (skip, mask, callback)->
15 | fs = require \fs
16 | path = require \path
17 | transform-mask =
18 | | mask.index-of(' ') > -1 => mask.split(' ')
19 | | mask is 'all' => ['**/*']
20 | | (mask ? '') is '' => ["*"]
21 | | _ => [mask]
22 | transform = (name)->
23 | is-dir = fs.lstat-sync(name).is-directory!
24 | base = path.basename name
25 | dir = (name)->
26 | name.yellow + \/
27 | res =
28 | | is-dir => dir name
29 | | _ => name
30 | res
31 | glob transform-mask, { silent: yes, strict: no }, (err, files)->
32 | if files?length > 0
33 | files |> p.map transform
34 | |> callback
--------------------------------------------------------------------------------
/commands/turn.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo)->
2 | repo.commands.push do
3 | name: \turn
4 | desc: "Rotate the table. Convert rows to cols and cols to rows. This command can replace concat and split commands"
5 | input: \lines
6 | output: \line
7 | enabled: yes
8 | doc:
9 | examples:
10 | * ''
11 | ...
12 | compile: ->
13 | Table = require \easy-table
14 | (mask, lines)->
15 | table = /[ ]+/
16 | config = if (mask ? "") is "" then table else mask
17 | arr = lines.map(-> it.split(config))
18 | newarr = []
19 | for i of arr
20 | for j of arr[i]
21 | if typeof newarr[j] is \undefined
22 | newarr[j] = []
23 | newarr[j][i] = arr[i][j]
24 | t = new Table
25 | switch config
26 | case table
27 | newarr.forEach (product)->
28 | product.forEach (item, i)->
29 | t.cell(i, item.replace(/[ ]/g,'_'))
30 | t.new-row!
31 | t.print!.trim!
32 | else
33 | newarr.map(-> it.join(config) ).join( \\n)
--------------------------------------------------------------------------------
/commands/order.ls:
--------------------------------------------------------------------------------
1 | module.exports = (repo, p)->
2 | repo.commands.push do
3 | name: "order"
4 | desc: "Sorts lines"
5 | input: \lines
6 | output: \lines
7 | enabled: yes
8 | compile: ->
9 | (mask, lines)->
10 | if (mask ? "") is ""
11 | lines |> p.sort
12 | else
13 | index = parse-int(mask)
14 | pad = (str, len) ->
15 | ((if str is '' then ' ' else str) + Array(len).join(' ')).slice 0, len
16 | maxes = []
17 | compare = (a, b) ->
18 | fun =
19 | | (a[index] + b[index]).to-string!.match(/[0-9]+/) => parse-int
20 | | _ => -> it
21 |
22 | res =
23 | | fun(a[index]) < fun(b[index]) => -1
24 | | fun(a[index]) > fun(b[index]) => 1
25 | | _ => 0
26 | res
27 | lines |> p.map (.split(/[ ]+/))
28 | |> p.each (s)->
29 | s.for-each (_, i)->
30 | maxes[i] = Math.max(s[i].length, maxes[i] ? 0)
31 | |> p.sort-with compare
32 | |> p.map (.map((item, c)-> pad(item, maxes[c])).join (' '))
33 |
--------------------------------------------------------------------------------
/generate.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | var fs, glob, p, isFile, updateJson, files;
4 | fs = require('fs');
5 | glob = require('glob');
6 | p = require('prelude-ls');
7 | isFile = function(name){
8 | return fs.existsSync(name) && fs.lstatSync(name).isFile();
9 | };
10 | updateJson = function(path, update){
11 | var file, save, json;
12 | file = isFile(path)
13 | ? require(path)
14 | : {};
15 | save = function(){
16 | return fs.writeFileSync(path, json, 'utf8');
17 | };
18 | update(file, save);
19 | json = JSON.stringify(file, null, 4);
20 | return save();
21 | };
22 | files = glob.sync('compiled-commands/*');
23 | updateJson('./package.json', function(model){
24 | var name, ref, names;
25 | name = function(filename){
26 | return filename.match("([a-z]+).[^.]+$")[1];
27 | };
28 | ref = function(it){
29 | return "./refs/" + it;
30 | };
31 | names = p.map(name)(
32 | files);
33 | names.forEach(function(it){
34 | return fs.writeFileSync(ref(it), "#!/usr/bin/env node\nrequire('../nixar.js')('" + it + "')", 'utf8');
35 | });
36 | return model.bin = p.pairsToObj(
37 | p.map(function(it){
38 | return [it, ref(it)];
39 | })(
40 | names));
41 | });
42 | }).call(this);
43 |
--------------------------------------------------------------------------------
/docs/cols.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "cols",
4 | "files": [
5 | "Native Command\nsh\n$ ls -la | awk '{print $1,$3}'\n
",
6 | "Print the first and third column of the text presented in a table
\n\nInput\nsh\ndrwxrwxr-x 4 ubuntu ubuntu 4096 Aug 12 07:38 ./\ndrwxr-xr-x 20 ubuntu ubuntu 4096 Aug 12 07:15 ../\ndrwxr-xr-x 3 ubuntu ubuntu 4096 Aug 7 15:20 .c9/\ndrwxr-xr-x 4 ubuntu ubuntu 4096 Aug 7 15:41 folder1/\n-rw-r--r-- 1 ubuntu ubuntu 507 Aug 11 12:25 rootfile.txt\n-rw-r--r-- 1 ubuntu ubuntu 572 Aug 8 23:01 rootfile2.txt\n
\n\nCommand\nsh\n$ ls -la | cols 1 3\n
\n\nOutput\nsh\ndrwxrwxr-x ubuntu\ndrwxr-xr-x ubuntu\ndrwxr-xr-x ubuntu\ndrwxr-xr-x ubuntu\n-rw-r--r-- ubuntu\n-rw-r--r-- ubuntu\n
",
7 | "Command\nsh\n$ cat filename.txt | awk 'BEGIN{RS=\", \"}{print}' | sed -e 's/word //g'\n
",
8 | "Command\nsh\n$ cat filename.txt | awk 'BEGIN{RS=\", \"}{print}' | awk '{print $1}'\n
",
9 | "input\nsh\nword skip, word skip, word skip, word skip, word skip\n
\n\nCommand\nsh\n$ cat filename.txt | split \", \" | cols 1\n
\n\nOutput\nsh\nword\nword\nword\nword\nword\n
"
10 | ]
11 | });
12 | }
--------------------------------------------------------------------------------
/compiled-commands/nixar.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "nixar",
6 | desc: "Shows all commands. Run `nixar killall` in order to kill all running nixar's commands",
7 | input: 'nothing',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(skip, mask, callback){
15 | var transform, cmd, exec;
16 | switch (mask != null ? mask : "") {
17 | case "":
18 | transform = function(c){
19 | return (c.name + " ").green + c.desc;
20 | };
21 | return callback(repo.commands.map(transform));
22 | case "killall":
23 | cmd = "killall -9 " + repo.commands.map(function(it){
24 | return it.name;
25 | }).join(" ");
26 | exec = require('child_process').exec;
27 | return exec(cmd, function(error, stdout, stderr){
28 | return callback(["killed"]);
29 | });
30 | default:
31 | return callback(repo.commands.filter(function(it){
32 | return it.name === mask;
33 | }).map(JSON.stringify));
34 | }
35 | };
36 | }
37 | });
38 | };
39 | }).call(this);
40 |
--------------------------------------------------------------------------------
/docs/fs.js:
--------------------------------------------------------------------------------
1 | module.exports = function(repo) {
2 | repo.docs.push({
3 | "name": "fs",
4 | "files": [
5 | "Native Command\nsh\n$ ls *.* #=> filename.txt rootfile.txt rootfile2.txt\n
",
6 | "Search files in the current directory
\n\nCommand\nsh\n$ fs *.* \n
\n\nOutput \nsh\nfilename.txt\nrootfile.txt\nrootfile2.txt\n
",
7 | "Command\nsh\n$ fs */ #=> folder1/ folder2/\n
",
8 | "Find and display all folders in the current directory
\n\nCommand\nsh\n$ fs */ #=> folder1/\n
",
9 | "Command\nsh\n$ ls -Rl\n
",
10 | "Recursive search for files and folders
\n\nCommand\nsh\n$ fs all \n
\n\nOutput \nsh\nfilename.txt\nfolder1/\nfolder1/folder1/\nfolder1/folder1/file.csv\nfolder1/folder1/file.txt\nfolder1/folder1/file2.csv\nfolder1/folder1/file2.txt\nfolder1/folder2/\nfolder1/folder2/file.csv\nfolder1/folder2/file1.txt\nrootfile.txt\nrootfile2.txt\n
",
11 | "Command\nsh\n$ find -mindepth 4 -type f -print\n
",
12 | "Recursive file search
\n\nCommand\nsh\n$ fs **/*.* \n
\n\nOutput \nsh\nfilename.txt\nfolder1/folder1/file.csv\nfolder1/folder1/file.txt\nfolder1/folder1/file2.csv\nfolder1/folder1/file2.txt\nfolder1/folder2/file.csv\nfolder1/folder2/file1.txt\nrootfile.txt\nrootfile2.txt\n
"
13 | ]
14 | });
15 | }
--------------------------------------------------------------------------------
/compiled-commands/cols.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p, parser){
4 | return repo.commands.push({
5 | name: 'cols',
6 | desc: "Get specific columns. Example: `cols 1-3 5 6 9-20`",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | return function(mask, lines){
15 | var pad, state, eachItem, makeColumns;
16 | pad = function(str, len){
17 | return ((str === '' ? ' ' : str) + Array(len).join(' ')).slice(0, len);
18 | };
19 | state = {
20 | maxes: [],
21 | columns: []
22 | };
23 | eachItem = function(s){
24 | return s.forEach(function(_, i){
25 | var ref$;
26 | return state.maxes[i] = Math.max(s[i].length, (ref$ = state.maxes[i]) != null ? ref$ : 0);
27 | });
28 | };
29 | makeColumns = function(it){
30 | state.columns = parser.numbers(mask, state.maxes.length - 1);
31 | return it;
32 | };
33 | return p.map(function(it){
34 | return it.map(function(item, c){
35 | return pad(item, state.maxes[c]);
36 | }).filter(function(item, i){
37 | return state.columns.indexOf(i) > -1;
38 | }).join(' ');
39 | })(
40 | makeColumns(
41 | p.each(eachItem)(
42 | p.map(function(it){
43 | return it.split(/[ ]+/);
44 | })(
45 | lines))));
46 | };
47 | }
48 | });
49 | };
50 | }).call(this);
51 |
--------------------------------------------------------------------------------
/compiled-commands/turn.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo){
4 | return repo.commands.push({
5 | name: 'turn',
6 | desc: "Rotate the table. Convert rows to cols and cols to rows. This command can replace concat and split commands",
7 | input: 'lines',
8 | output: 'line',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | var Table;
15 | Table = require('easy-table');
16 | return function(mask, lines){
17 | var table, config, arr, newarr, i, j, t;
18 | table = /[ ]+/;
19 | config = (mask != null ? mask : "") === "" ? table : mask;
20 | arr = lines.map(function(it){
21 | return it.split(config);
22 | });
23 | newarr = [];
24 | for (i in arr) {
25 | for (j in arr[i]) {
26 | if (typeof newarr[j] === 'undefined') {
27 | newarr[j] = [];
28 | }
29 | newarr[j][i] = arr[i][j];
30 | }
31 | }
32 | t = new Table;
33 | switch (config) {
34 | case table:
35 | newarr.forEach(function(product){
36 | product.forEach(function(item, i){
37 | return t.cell(i, item.replace(/[ ]/g, '_'));
38 | });
39 | return t.newRow();
40 | });
41 | return t.print().trim();
42 | default:
43 | return newarr.map(function(it){
44 | return it.join(config);
45 | }).join('\n');
46 | }
47 | };
48 | }
49 | });
50 | };
51 | }).call(this);
52 |
--------------------------------------------------------------------------------
/compiled-commands/fs.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "fs",
6 | desc: "Finds file(s) by glob-like mask (*.* or **/*.* or */ or all)",
7 | input: 'nothing',
8 | output: 'lines',
9 | enabled: true,
10 | doc: {
11 | examples: ['']
12 | },
13 | compile: function(){
14 | var glob;
15 | glob = require('glob-all');
16 | return function(skip, mask, callback){
17 | var fs, path, transformMask, transform;
18 | fs = require('fs');
19 | path = require('path');
20 | transformMask = (function(){
21 | switch (false) {
22 | case !(mask.indexOf(' ') > -1):
23 | return mask.split(' ');
24 | case mask !== 'all':
25 | return ['**/*'];
26 | case (mask != null ? mask : '') !== '':
27 | return ["*"];
28 | default:
29 | return [mask];
30 | }
31 | }());
32 | transform = function(name){
33 | var isDir, base, dir, res;
34 | isDir = fs.lstatSync(name).isDirectory();
35 | base = path.basename(name);
36 | dir = function(name){
37 | return name.yellow + '/';
38 | };
39 | res = (function(){
40 | switch (false) {
41 | case !isDir:
42 | return dir(name);
43 | default:
44 | return name;
45 | }
46 | }());
47 | return res;
48 | };
49 | return glob(transformMask, {
50 | silent: true,
51 | strict: false
52 | }, function(err, files){
53 | if ((files != null ? files.length : void 8) > 0) {
54 | return callback(
55 | p.map(transform)(
56 | files));
57 | }
58 | });
59 | };
60 | }
61 | });
62 | };
63 | }).call(this);
64 |
--------------------------------------------------------------------------------
/compiled-commands/order.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(repo, p){
4 | return repo.commands.push({
5 | name: "order",
6 | desc: "Sorts lines",
7 | input: 'lines',
8 | output: 'lines',
9 | enabled: true,
10 | compile: function(){
11 | return function(mask, lines){
12 | var index, pad, maxes, compare;
13 | if ((mask != null ? mask : "") === "") {
14 | return p.sort(
15 | lines);
16 | } else {
17 | index = parseInt(mask);
18 | pad = function(str, len){
19 | return ((str === '' ? ' ' : str) + Array(len).join(' ')).slice(0, len);
20 | };
21 | maxes = [];
22 | compare = function(a, b){
23 | var fun, res;
24 | fun = (function(){
25 | switch (false) {
26 | case !(a[index] + b[index]).toString().match(/[0-9]+/):
27 | return parseInt;
28 | default:
29 | return function(it){
30 | return it;
31 | };
32 | }
33 | }());
34 | res = (function(){
35 | switch (false) {
36 | case !(fun(a[index]) < fun(b[index])):
37 | return -1;
38 | case !(fun(a[index]) > fun(b[index])):
39 | return 1;
40 | default:
41 | return 0;
42 | }
43 | }());
44 | return res;
45 | };
46 | return p.map(function(it){
47 | return it.map(function(item, c){
48 | return pad(item, maxes[c]);
49 | }).join(' ');
50 | })(
51 | p.sortWith(compare)(
52 | p.each(function(s){
53 | return s.forEach(function(_, i){
54 | var ref$;
55 | return maxes[i] = Math.max(s[i].length, (ref$ = maxes[i]) != null ? ref$ : 0);
56 | });
57 | })(
58 | p.map(function(it){
59 | return it.split(/[ ]+/);
60 | })(
61 | lines))));
62 | }
63 | };
64 | }
65 | });
66 | };
67 | }).call(this);
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Website address is 'http://askucher.github.io/nixarweb/#/'
2 |
3 | # New shell commands
4 | Joyable equivalents for existent linux commands
5 |
6 | 
7 |
8 | npm install -g nixar
9 |
10 | ###Commands
11 |
12 | #### after
13 | Prints everything after [mask]. Has option 'after last [mask]'
14 | #### before
15 | Prints everything before mask
16 | #### cols
17 | Get specific columns. Example: `cols 1-3 5 6 9-20`
18 | #### concat
19 | Joins lines into one line
20 | #### content
21 | Prints content, content lines, content created date, content modified date, content size
22 | #### count
23 | Calculates lines count
24 | #### drop
25 | Drops lines
26 | #### exclude
27 | Excludes line specified by mask
28 | #### filter
29 | Filter lines
30 | #### fs
31 | Finds file(s) by glob-like mask (*.* or **/*.* or */ or all)
32 | #### length
33 | Calculates characters count
34 | #### log
35 | Logs output to file and continues printing
36 | #### lower
37 | Converts characters to lowercase
38 | #### map
39 | Transforms line
40 | #### mark
41 | Highlights lines' parts according to the provided mask
42 | #### max
43 | Calculates maximum number from list of numbers
44 | #### min
45 | Calculates minimum number from list of numbers
46 | #### nixar
47 | Shows all commands. Run `nixar killall` in order to kill all running nixar's commands
48 | #### order
49 | Sorts lines
50 | #### remove
51 | Removes substring in line
52 | #### replace
53 | Replaces substring in line
54 | #### reverse
55 | Reverses the order of output
56 | #### rows
57 | Gets specific rows
58 | #### show
59 | Prints file, file lines, file created date, file modified date
60 | #### split
61 | Splits line into lines
62 | #### substr
63 | Returns the part of string specified by start and length parameters
64 | #### sum
65 | Calc sum of numbers in list
66 | #### table
67 | Create columns from line based on separator
68 | #### take
69 | Select lines
70 | #### trim
71 | Remove spaces from start and end of line. But if you provide the substring it will remove it from start and end of line
72 | #### turn
73 | Rotate the table. Convert rows to cols and cols to rows. This command can replace concat and split commands
74 | #### unique
75 | Get unique records
76 | #### upper
77 | Convert characters to uppercase
78 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "nixar.js",
4 | "compiled-commands",
5 | "refs",
6 | "docs"
7 | ],
8 | "name": "nixar",
9 | "description": "map, filter and other functions for unix bash",
10 | "version": "0.1.2045",
11 | "uperversion": "0.1",
12 | "subversion": 2045,
13 | "homepage": "https://github.com/gruntjs/",
14 | "author": {
15 | "name": "xm",
16 | "url": ""
17 | },
18 | "licenses": [
19 | {
20 | "type": "MIT",
21 | "url": "https://github.com/askucher/nixar/blob/master/LICENSE-MIT"
22 | }
23 | ],
24 | "engines": {
25 | "node": ">= 0.8.0"
26 | },
27 | "scripts": {
28 | "test": "grunt test"
29 | },
30 | "dependencies": {
31 | "xonom": "^0.1.74",
32 | "yargs": "^3.21.0",
33 | "highlight": "^0.2.3",
34 | "glob-all": "^3.0.1",
35 | "glob": "^6.0.1",
36 | "event-stream": "^3.3.1",
37 | "easy-table": "^1.0.0",
38 | "colors": "^1.1.2",
39 | "readline": "0.0.8",
40 | "prelude-ls": "^1.1.2",
41 | "picture-tube": "^1.0.0",
42 | "node-syntaxhighlighter": "^0.8.1",
43 | "moment": "^2.10.6",
44 | "html-to-json": "^0.5.1"
45 | },
46 | "devDependencies": {},
47 | "peerDependencies": {},
48 | "keywords": [],
49 | "bin": {
50 | "unique": "./refs/unique",
51 | "drop": "./refs/drop",
52 | "count": "./refs/count",
53 | "content": "./refs/content",
54 | "concat": "./refs/concat",
55 | "cols": "./refs/cols",
56 | "before": "./refs/before",
57 | "after": "./refs/after",
58 | "filter": "./refs/filter",
59 | "upper": "./refs/upper",
60 | "max": "./refs/max",
61 | "mark": "./refs/mark",
62 | "map": "./refs/map",
63 | "lower": "./refs/lower",
64 | "log": "./refs/log",
65 | "length": "./refs/length",
66 | "fs": "./refs/fs",
67 | "exclude": "./refs/exclude",
68 | "min": "./refs/min",
69 | "nixar": "./refs/nixar",
70 | "order": "./refs/order",
71 | "remove": "./refs/remove",
72 | "replace": "./refs/replace",
73 | "reverse": "./refs/reverse",
74 | "rows": "./refs/rows",
75 | "show": "./refs/show",
76 | "split": "./refs/split",
77 | "substr": "./refs/substr",
78 | "sum": "./refs/sum",
79 | "table": "./refs/table",
80 | "take": "./refs/take",
81 | "trim": "./refs/trim",
82 | "turn": "./refs/turn"
83 | },
84 | "repository": {
85 | "type": "git",
86 | "url": "git@github.com:askucher/nixar.git"
87 | },
88 | "_id": "prelude@0.6.0",
89 | "dist": {},
90 | "_from": "prelude@>0.1",
91 | "_npmVersion": "0.1.00",
92 | "_npmUser": {
93 | "name": "askucher",
94 | "email": "a.stegno@gmail.com"
95 | },
96 | "maintainers": [],
97 | "directories": {},
98 | "bugs": {
99 | "url": "https://github.com/askucher/nixar/issues"
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/nixar.ls:
--------------------------------------------------------------------------------
1 | module.exports = (cmd)->
2 | load =
3 | | cmd is \nixar => \*
4 | | _ => cmd
5 | process.title = cmd
6 | require \xonom
7 | .service \start, ->
8 | .run ->
9 | require \colors
10 | .service \p, ->
11 | require \prelude-ls
12 | .service \repo, ->
13 | commands: []
14 | .service \parser, (p)->
15 | numbers: (mask, last)->
16 | return [0] if (mask ? "") is ""
17 | index = (str)->
18 | str |> parse-int |> (-> it - 1)
19 | transform = (str)->
20 | get-int = (str)->
21 | | str is \first => 0
22 | | str is \last => last
23 | | _ => index str
24 | args =
25 | str |> p.split \-
26 | |> p.map -> get-int it
27 | res =
28 | | args.length < 2 => get-int str
29 | | _ => [args.0 to args.1]
30 | res
31 | mask |> p.split(/[ ]+/)
32 | |> p.map transform
33 | |> p.flatten
34 | .service \cat, ->
35 | compile: ->
36 | fs = require \fs
37 | moment = require \moment
38 | nsh = require \node-syntaxhighlighter
39 | hl = require(\highlight).Highlight
40 | parser = require \html-to-json
41 | highlight = (code, type, callback) ->
42 | language = nsh.get-language(type, no)
43 | if language?
44 | process = (item) ->
45 | type = if item.attribs then item.attribs[\class] else \text
46 | children = (color)->
47 | content = item.children.map(process)
48 | lines = if color? then content.map(-> it[color]) else content
49 | if lines.0 is null then null else lines.join("")
50 | switch type?match(/^[a-z]+/)?0
51 | when \text
52 | return null if item.data isnt " " and item.parent?attribs?class?match(/^[a-z]+/)?0 is 'line'
53 | item.data
54 | when \gutter
55 | children \blue
56 | when \code
57 | children \green
58 | when \keyword
59 | children \green
60 | when \plain
61 | children!
62 | when \line
63 | data = children!
64 | if data isnt null
65 | data + \\n
66 | else ""
67 | when ''
68 | children!
69 | else
70 | children \yellow
71 | parser.parse nsh.highlight(code, language), (err, data) ->
72 | res = process(data.root!.0)
73 | callback res.substr(0, res.last-index-of(\\n))
74 | else
75 | replacer = (str)->
76 | type = str.match('class="([a-z]+)"').1
77 | value = str.match(">([^<]+)<").1
78 | switch type
79 | case \keyword
80 | value.green
81 | case \string
82 | value.yellow
83 | case \number
84 | value.magenta
85 | else
86 | value
87 | callback hl(code).replace(/<\/?[a-z]+[^>]*>[^<]+<\/[^>]+>/g, replacer)
88 | es = require \event-stream
89 | pictureTube = require \picture-tube
90 |
91 | (mask, input, callback)->
92 | path = process.cwd! + \/ + input
93 | extension = path.match(/[a-z]+$/)?0
94 | lines = ->
95 | fs.read-file-sync(input).to-string(\utf8).split(/\n/)
96 | if !fs.exists-sync(path)
97 | callback ["file '#path' not exists"]
98 | return
99 | stats = fs.lstat-sync(path)
100 | if !stats.is-file!
101 | callback ["'#path' is not a file"]
102 | else if (mask ? "") isnt ""
103 | callback do
104 | switch mask
105 | case \lines
106 | lines!.map(-> "#input ".yellow + it)
107 | case \modified
108 | ["#input ".yellow + moment(moment!).diff(stats[\mtime], \seconds).to-string! + ' seconds ago'.gray + ' ' + stats[\mtime] ]
109 | case \created
110 | ["#input ".yellow + moment(moment!).diff(stats[\ctime], \seconds).to-string! + ' seconds ago'.gray + ' ' + stats[\ctime] ]
111 | case \size
112 | size = parse-int stats[\size]
113 | colored = (num, w)->
114 | if num > 0 then "#num #w" else "#num #w".gray
115 | arr =
116 | * "#input".yellow
117 | * colored(size, "b")
118 | * "/".gray
119 | * colored(Math.round( size / 1024 ), \kb)
120 | * "/".gray
121 | * colored(Math.round( size / 1024^2 ), \mb)
122 | * "/".gray
123 | * colored(Math.round( size / 1024^3 ), \gb)
124 | [arr.join(' ')]
125 | else 'mask is not supported'
126 | else if extension isnt \png
127 | highlight lines!.join("\n"), extension, (data)->
128 | callback [data]
129 | else
130 | res = []
131 | tube = new picture-tube!
132 | print = (data)->
133 | res.push data.to-string!
134 | end = ->
135 | callback [res.join('')]
136 | res.length = 0
137 | fs.create-read-stream(input).pipe(tube).pipe(es.through(print, end))
138 | .run "#{__dirname}/compiled-commands/#load.js"
139 | .run (repo, p)->
140 | jargs =
141 | require('yargs')
142 | .completion \completion , (current, argv)->
143 | ['foo','bar']
144 | .argv
145 | argv = jargs._.join(' ')
146 |
147 | timer = null
148 |
149 | set-timer = ->
150 | clear-timeout timer
151 | timer =
152 | set-timeout do
153 | * ->
154 | process.exit 0
155 | * 20 * 1000
156 | lines = []
157 | print = (res)->
158 | console.log(res) if res?
159 | #set-timer!
160 | print-lines = (items)->
161 | items?for-each(print)
162 | #process.exit 0
163 | const commands =
164 | repo.commands
165 | commands |> p.filter -> it.aliases? and it.enabled
166 | |> p.map (com)-> com.aliases.map(-> name: it, compile: com.compile, input: com.input, output: com.output )
167 | |> p.flatten
168 | |> p.each commands~push
169 |
170 | build = (type)->
171 | commands |> p.filter(-> it.enabled)
172 | |> p.filter(-> "#{it.input}-#{it.output}" is type)
173 | |> p.map(-> [it.name, it.compile!] )
174 | |> p.pairs-to-obj
175 | nothing-lines = build \nothing-lines
176 | line-lines = build \line-lines
177 | line-line = build \line-line
178 | lines-lines = build \lines-lines
179 | lines-line = build \lines-line
180 |
181 | if nothing-lines[cmd]?
182 | nothing-lines[cmd]?(null, argv, print-lines)
183 | #process.exit 0
184 | return
185 | readline = require \readline
186 | rl = readline.create-interface do
187 | input: process.stdin
188 | output: process.stdout
189 | terminal: no
190 | rl.on \line, (line)->
191 | if line-lines[cmd]? or line-line[cmd]?
192 | line-lines[cmd]?(argv, line, print-lines)
193 | print line-line[cmd]?(argv,line)
194 | else
195 | lines.push(line)
196 | rl.on \close, ->
197 | lines-lines[cmd]?(argv, lines)?for-each(print)
198 | res = lines-line[cmd]?(argv, lines)
199 | if res?
200 | print res
201 | process.exit 0
--------------------------------------------------------------------------------
/nixar.js:
--------------------------------------------------------------------------------
1 | // Generated by LiveScript 1.3.1
2 | (function(){
3 | module.exports = function(cmd){
4 | var load;
5 | load = (function(){
6 | switch (false) {
7 | case cmd !== 'nixar':
8 | return '*';
9 | default:
10 | return cmd;
11 | }
12 | }());
13 | process.title = cmd;
14 | return require('xonom').service('start', function(){}).run(function(){
15 | return require('colors');
16 | }).service('p', function(){
17 | return require('prelude-ls');
18 | }).service('repo', function(){
19 | return {
20 | commands: []
21 | };
22 | }).service('parser', function(p){
23 | return {
24 | numbers: function(mask, last){
25 | var index, transform;
26 | if ((mask != null ? mask : "") === "") {
27 | return [0];
28 | }
29 | index = function(str){
30 | return function(it){
31 | return it - 1;
32 | }(
33 | parseInt(
34 | str));
35 | };
36 | transform = function(str){
37 | var getInt, args, res;
38 | getInt = function(str){
39 | switch (false) {
40 | case str !== 'first':
41 | return 0;
42 | case str !== 'last':
43 | return last;
44 | default:
45 | return index(str);
46 | }
47 | };
48 | args = p.map(function(it){
49 | return getInt(it);
50 | })(
51 | p.split('-')(
52 | str));
53 | res = (function(){
54 | var i$, to$, results$ = [];
55 | switch (false) {
56 | case !(args.length < 2):
57 | return getInt(str);
58 | default:
59 | for (i$ = args[0], to$ = args[1]; i$ <= to$; ++i$) {
60 | results$.push(i$);
61 | }
62 | return results$;
63 | }
64 | }());
65 | return res;
66 | };
67 | return p.flatten(
68 | p.map(transform)(
69 | p.split(/[ ]+/)(
70 | mask)));
71 | }
72 | };
73 | }).service('cat', function(){
74 | return {
75 | compile: function(){
76 | var fs, moment, nsh, hl, parser, highlight, es, pictureTube;
77 | fs = require('fs');
78 | moment = require('moment');
79 | nsh = require('node-syntaxhighlighter');
80 | hl = require('highlight').Highlight;
81 | parser = require('html-to-json');
82 | highlight = function(code, type, callback){
83 | var language, process, replacer;
84 | language = nsh.getLanguage(type, false);
85 | if (language != null) {
86 | process = function(item){
87 | var type, children, ref$, ref1$, ref2$, ref3$, ref4$, data;
88 | type = item.attribs ? item.attribs['class'] : 'text';
89 | children = function(color){
90 | var content, lines;
91 | content = item.children.map(process);
92 | lines = color != null ? content.map(function(it){
93 | return it[color];
94 | }) : content;
95 | if (lines[0] === null) {
96 | return null;
97 | } else {
98 | return lines.join("");
99 | }
100 | };
101 | switch (type != null && ((ref$ = type.match(/^[a-z]+/)) != null && ref$[0])) {
102 | case 'text':
103 | if (item.data !== " " && ((ref1$ = item.parent) != null ? (ref2$ = ref1$.attribs) != null ? (ref3$ = ref2$['class']) != null ? (ref4$ = ref3$.match(/^[a-z]+/)) != null ? ref4$[0] : void 8 : void 8 : void 8 : void 8) === 'line') {
104 | return null;
105 | }
106 | return item.data;
107 | case 'gutter':
108 | return children('blue');
109 | case 'code':
110 | return children('green');
111 | case 'keyword':
112 | return children('green');
113 | case 'plain':
114 | return children();
115 | case 'line':
116 | data = children();
117 | if (data !== null) {
118 | return data + '\n';
119 | } else {
120 | return "";
121 | }
122 | break;
123 | case '':
124 | return children();
125 | default:
126 | return children('yellow');
127 | }
128 | };
129 | return parser.parse(nsh.highlight(code, language), function(err, data){
130 | var res;
131 | res = process(data.root()[0]);
132 | return callback(res.substr(0, res.lastIndexOf('\n')));
133 | });
134 | } else {
135 | replacer = function(str){
136 | var type, value;
137 | type = str.match('class="([a-z]+)"')[1];
138 | value = str.match(">([^<]+)<")[1];
139 | switch (type) {
140 | case 'keyword':
141 | return value.green;
142 | case 'string':
143 | return value.yellow;
144 | case 'number':
145 | return value.magenta;
146 | default:
147 | return value;
148 | }
149 | };
150 | return callback(hl(code).replace(/<\/?[a-z]+[^>]*>[^<]+<\/[^>]+>/g, replacer));
151 | }
152 | };
153 | es = require('event-stream');
154 | pictureTube = require('picture-tube');
155 | return function(mask, input, callback){
156 | var path, extension, ref$, lines, stats, size, colored, arr, res, tube, print, end;
157 | path = process.cwd() + '/' + input;
158 | extension = (ref$ = path.match(/[a-z]+$/)) != null ? ref$[0] : void 8;
159 | lines = function(){
160 | return fs.readFileSync(input).toString('utf8').split(/\n/);
161 | };
162 | if (!fs.existsSync(path)) {
163 | callback(["file '" + path + "' not exists"]);
164 | return;
165 | }
166 | stats = fs.lstatSync(path);
167 | if (!stats.isFile()) {
168 | return callback(["'" + path + "' is not a file"]);
169 | } else if ((mask != null ? mask : "") !== "") {
170 | return callback((function(){
171 | switch (mask) {
172 | case 'lines':
173 | return lines().map(function(it){
174 | return (input + " ").yellow + it;
175 | });
176 | case 'modified':
177 | return [(input + " ").yellow + moment(moment()).diff(stats['mtime'], 'seconds').toString() + ' seconds ago'.gray + ' ' + stats['mtime']];
178 | case 'created':
179 | return [(input + " ").yellow + moment(moment()).diff(stats['ctime'], 'seconds').toString() + ' seconds ago'.gray + ' ' + stats['ctime']];
180 | case 'size':
181 | size = parseInt(stats['size']);
182 | colored = function(num, w){
183 | if (num > 0) {
184 | return num + " " + w;
185 | } else {
186 | return (num + " " + w).gray;
187 | }
188 | };
189 | arr = [(input + "").yellow, colored(size, "b"), "/".gray, colored(Math.round(size / 1024), 'kb'), "/".gray, colored(Math.round(size / Math.pow(1024, 2)), 'mb'), "/".gray, colored(Math.round(size / Math.pow(1024, 3)), 'gb')];
190 | return [arr.join(' ')];
191 | default:
192 | return 'mask is not supported';
193 | }
194 | }()));
195 | } else if (extension !== 'png') {
196 | return highlight(lines().join("\n"), extension, function(data){
197 | return callback([data]);
198 | });
199 | } else {
200 | res = [];
201 | tube = new pictureTube();
202 | print = function(data){
203 | return res.push(data.toString());
204 | };
205 | end = function(){
206 | callback([res.join('')]);
207 | return res.length = 0;
208 | };
209 | return fs.createReadStream(input).pipe(tube).pipe(es.through(print, end));
210 | }
211 | };
212 | }
213 | };
214 | }).run(__dirname + "/compiled-commands/" + load + ".js").run(function(repo, p){
215 | var jargs, argv, timer, setTimer, lines, print, printLines, commands, build, nothingLines, lineLines, lineLine, linesLines, linesLine, readline, rl;
216 | jargs = require('yargs').completion('completion', function(current, argv){
217 | return ['foo', 'bar'];
218 | }).argv;
219 | argv = jargs._.join(' ');
220 | timer = null;
221 | setTimer = function(){
222 | var timer;
223 | clearTimeout(timer);
224 | return timer = setTimeout(function(){
225 | return process.exit(0);
226 | }, 20 * 1000);
227 | };
228 | lines = [];
229 | print = function(res){
230 | if (res != null) {
231 | return console.log(res);
232 | }
233 | };
234 | printLines = function(items){
235 | return items != null ? items.forEach(print) : void 8;
236 | };
237 | commands = repo.commands;
238 | p.each(bind$(commands, 'push'))(
239 | p.flatten(
240 | p.map(function(com){
241 | return com.aliases.map(function(it){
242 | return {
243 | name: it,
244 | compile: com.compile,
245 | input: com.input,
246 | output: com.output
247 | };
248 | });
249 | })(
250 | p.filter(function(it){
251 | return it.aliases != null && it.enabled;
252 | })(
253 | commands))));
254 | build = function(type){
255 | return p.pairsToObj(
256 | p.map(function(it){
257 | return [it.name, it.compile()];
258 | })(
259 | p.filter(function(it){
260 | return it.input + "-" + it.output === type;
261 | })(
262 | p.filter(function(it){
263 | return it.enabled;
264 | })(
265 | commands))));
266 | };
267 | nothingLines = build('nothing-lines');
268 | lineLines = build('line-lines');
269 | lineLine = build('line-line');
270 | linesLines = build('lines-lines');
271 | linesLine = build('lines-line');
272 | if (nothingLines[cmd] != null) {
273 | if (typeof nothingLines[cmd] == 'function') {
274 | nothingLines[cmd](null, argv, printLines);
275 | }
276 | return;
277 | }
278 | readline = require('readline');
279 | rl = readline.createInterface({
280 | input: process.stdin,
281 | output: process.stdout,
282 | terminal: false
283 | });
284 | rl.on('line', function(line){
285 | if (lineLines[cmd] != null || lineLine[cmd] != null) {
286 | if (typeof lineLines[cmd] == 'function') {
287 | lineLines[cmd](argv, line, printLines);
288 | }
289 | return print(typeof lineLine[cmd] == 'function' ? lineLine[cmd](argv, line) : void 8);
290 | } else {
291 | return lines.push(line);
292 | }
293 | });
294 | return rl.on('close', function(){
295 | var ref$, res;
296 | if (typeof linesLines[cmd] == 'function') {
297 | if ((ref$ = linesLines[cmd](argv, lines)) != null) {
298 | ref$.forEach(print);
299 | }
300 | }
301 | res = typeof linesLine[cmd] == 'function' ? linesLine[cmd](argv, lines) : void 8;
302 | if (res != null) {
303 | print(res);
304 | }
305 | return process.exit(0);
306 | });
307 | });
308 | };
309 | function bind$(obj, key, target){
310 | return function(){ return (target || obj)[key].apply(obj, arguments) };
311 | }
312 | }).call(this);
313 |
--------------------------------------------------------------------------------