Skip to content

Commit b168d54

Browse files
committed
Split utils some more, start reorganizing make, move library to assembly
1 parent a11dca2 commit b168d54

62 files changed

Lines changed: 664 additions & 845 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
7777
1. [cut](cut.sh)
7878
1. [Eclipse](eclipse.md)
7979
1. [expand](expand.md)
80+
1. [fold](fold.md)
8081
1. [paste](paste.md)
8182
1. [printf](printf.sh)
8283
1. [sed](sed.sh)
84+
1. [strings](strings.md)
8385
1. [tabs](tabs.md)
86+
1. [uniq](uniq.md)
8487
1. [wc](wc.md)
8588
1. Binary data viewers
8689
1. [hd](hd.md)
@@ -92,26 +95,23 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
9295
1. [diff](diff.md)
9396
1. [wdiff](diff.md)
9497
1. Files, directories
95-
1. [cp](cp.sh)
96-
1. [dd](dd.md)
97-
1. [du](du.md)
98-
1. [fdupes](fdupes.md)
99-
1. [find](find.md)
100-
1. links
98+
1. [cp](cp.sh)
99+
1. [dd](dd.md)
100+
1. [du](du.md)
101+
1. [fdupes](fdupes.md)
102+
1. [find](find.md)
103+
1. links
101104
1. [ln](ln.md)
102105
1. [readlink](readlink.md)
103106
1. [realpath](realpath.md)
104-
1. [locate](locate.md)
105-
1. [ls](ls.md)
106-
1. [read](read.md)
107-
1. [stat](stat.md)
108-
1. [tree](tree.md)
107+
1. [locate](locate.md)
108+
1. [ls](ls.md)
109+
1. [read](read.md)
110+
1. [stat](stat.md)
111+
1. [tree](tree.md)
109112
1. File managers
110113
1. [Krusader](krusader.md)
111114
1. [vifm](vifm.md)
112-
1. [Compilation and libraries](compile.md)
113-
1. [GDB](gdb.md)
114-
1. [Library](library.md)
115115
1. Programming
116116
1. [ack](ack.sh)
117117
1. [ctags](ctags/)
@@ -193,15 +193,23 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
193193
1. [chef](chef/)
194194
1. [puppet](puppet.md)
195195
1. Printing
196-
1. [CUPS](cups.md)
196+
1. [CUPS](cups.md)
197197
1. [lp](lp.md)
198198
1. [lpstat](lpstat.md)
199199
1. [lpoptions](lpoptions.md)
200200
1. [system-config-printer](system-config-printer.md)
201+
1. Math
202+
1. [bc](bc.md)
203+
1. [factor](factor.md)
204+
1. [primes](primes.md)
205+
1. [seq](seq.md)
206+
1. [shuf](shuf.md)
207+
1. Sorting
208+
1. [sort](sort.md)
209+
1. [tsort](tsort.md)
201210
1. Misc
202211
1. [cron](cron.sh)
203212
1. [logrotate](logrotate.md)
204-
1. [factor](factor.md)
205213
1. [xargs](xargs.md)
206214
1. [Bibliography](bibliography.md)
207215

awk.sh

100644100755
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# POSIX 7. <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html>
3+
# POSIX 7. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
44

55
# Turing Machine, but use only for *ultra simple* POSIX text table field manipulation:
66
# it only has better golfing on that very limited problem set.
@@ -46,7 +46,7 @@
4646
#CONDITION_N { STATEMENT_N }
4747
#END { STATEMENT_END }
4848

49-
echo $'1 2\n3 4' | awk 'BEGIN{print "b"}1<2{print "l"}1<2{print "l2"; print "l3"}1>2{print "l4"}END{print "e"}'
49+
printf '1 2\n3 4' | awk 'BEGIN{print "b"}1<2{print "l"}1<2{print "l2"; print "l3"}1>2{print "l4"}END{print "e"}'
5050
#$'b\nl\nl2\nl3\nl\nl2\nl3\ne
5151

5252
echo '0.5 0.5' | awk '{print $1+$2}'
@@ -63,11 +63,11 @@
6363
awk 'BEGIN{print "a", 1}'
6464
#'a 1'
6565
#by default, print does space separation
66-
awk 'BEGIN{print "a"."b"}'
66+
awk 'BEGIN{print "a" "b"}'
6767
#'ab'
6868
#string concat
69-
awk '{print}'
70-
#cat
69+
70+
[ "$(echo 'a' | awk '{print}')" = 'a' ] || exit 1
7171

7272
## applications
7373

@@ -81,8 +81,25 @@
8181

8282
# Same as above, but print only first match:
8383

84-
[ "$(echo $'1 a\n2 b\n1 c' | awk '$1 == 1 { print $2; exit }')" = a ] || exit 1
84+
[ "$(printf '1 a\n2 b\n1 c\n' | awk '$1 == 1 { print $2; exit }')" = 'a' ] || exit 1
8585

8686
# Same as above, but match EREs:
8787

88-
[ "$(echo $'1 a\n2 b\n1 c' | awk '$1 ~/^1$/ { print $2; exit }')" = a ] || exit 1
88+
[ "$(printf '1 a\n2 b\n1 c\n' | awk '$1 ~/^1$/ { print $2; exit }')" = 'a' ] || exit 1
89+
90+
## RS
91+
92+
# Record separator.
93+
94+
# `''` is a special value that selects blank lines, i.e. paragraphs:
95+
# http://unix.stackexchange.com/questions/82944/how-to-grep-for-text-in-a-file-and-display-the-paragraph-that-has-the-text/82958#82958
96+
97+
[ "$(printf '1 a0\na1\na2\n\nb0\nb1\nb2\n\nc0\nc1\nc2\n' | awk -v RS='' '/b1/')" = "$(printf 'b0\nb1\nb2')" ] || exit 1
98+
99+
## Subtract adjacent lines
100+
101+
# TODO fails if the first is zero.
102+
103+
#[ "$(printf '0\n1\n3\n6' | awk awk 'p{print $0-p}{p=$0}')" = "$(printf '1\n2\n3')" ] || exit 1
104+
105+
echo 'ALL ASSERTS PASSED'

bc.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# bc
22

3-
POSIX
3+
POSIX: <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html>
44

55
Simple interpreted language, calculator focus.
66

7-
Cute toy language that only exists because it is POSIX =),
8-
but is completely superseded by any modern interpreted language,
9-
and only golfs very slightly better than Python.
7+
Cute toy language that only exists because it is POSIX =)
108

11-
C like syntax.
9+
Completely superseded by any modern interpreted language, and only golfs very slightly better than Python, which also has arbitrary precision calculation out of the box.
10+
11+
C-like syntax.
1212

1313
Features: variable definition, function definition, arrays, strings
1414

cups.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Port: 631 TCP and UDP.
1010

1111
You can also visit: <http://localhost:631/> to see a web front-end for CUPS. TODO check: is it standard? Works on Ubuntu 14.04.
1212

13-
Configuration files:
13+
## Ink levels
14+
15+
Not possible with CUPS apparently. Consider `ink`.
1416

1517
## Bibliography
1618

dot/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
IN_EXT := .dot
22
OUT_EXT := .dot
33

4-
INS := $(wildcard *$(IN_EXT))
5-
OUTS_SVG := $(patsubst %$(IN_EXT),%.svg,$(INS))
6-
OUTS_PNG := $(patsubst %$(IN_EXT),%.png,$(INS))
4+
INS := $(wildcard *$(IN_EXT))
5+
OUTS_SVG := $(patsubst %$(IN_EXT),%.svg,$(INS))
6+
OUTS_PNG := $(patsubst %$(IN_EXT),%.png,$(INS))
77

88
.PHONY: all clean
99

1010
all: $(OUTS_SVG) $(OUTS_PNG)
1111

1212
%.svg: %$(IN_EXT)
13-
dot -Tsvg "$<" > "$@"
13+
dot -Tsvg '$<' > '$@'
1414

1515
%.png: %$(IN_EXT)
16-
dot -Tpng "$<" > "$@"
16+
dot -Tpng '$<' > '$@'
1717

1818
clean:
1919
rm *.svg *.png

dot/digraph.dot

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// # Directed graph.
22
digraph graphname {
3-
3 -> 1;
43
1 -> 0;
54
1 -> 2;
6-
3 -> 4;
75
}

factor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# factor
22

3-
Coreutils.
3+
Coreutils: <https://www.gnu.org/software/coreutils/manual/html_node/factor-invocation.html>
44

55
Factor a number into prime constituents.
66

7-
[ "`factor 30`" = "30: 2 3 5" ] || exit 1
7+
[ "$(factor 30)" = '30: 2 3 5' ] || exit 1

fold.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# fold
2+
3+
POSIX 7: <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/fold.html>
4+
5+
Wrap lines:
6+
7+
[ "$(printf "aaaa\nbb" | fold -w 3)" = "$(printf 'aaa\na\nbb\n')" ] || exit 1
8+
9+
`-s`: only break at spaces:
10+
11+
[ "$(printf "12345 6\n" | fold -s -w 3)" = "$(printf '123\n45 \n6\n')" ] || exit 1

game.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ Displays the phase of the moon.
8484

8585
[ "$(echo 'abc' | rot13)" = 'nop' ] || exit 1
8686

87-
#### primes
88-
89-
Print primes between 1 to 100:
90-
91-
primes 1 100
92-
93-
Count primes:
94-
95-
primes 1 100 | wc -l
96-
97-
`factor` is not included here as it is part of coreutils.
98-
9987
#### robots
10088

10189
Very simple, fun, but too much luck.

ink.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ink
2+
3+
Check printer ink levels.
4+
5+
CLI front-end for libinklevel.
6+
7+
Works for many printers, but not all.
8+
9+
TODO usage

0 commit comments

Comments
 (0)