diff --git a/echo.nim b/echo.nim index ae894c6..093c39e 100644 --- a/echo.nim +++ b/echo.nim @@ -2,8 +2,8 @@ import cligen, sequtils import common proc main(strings:seq[string], newline=true) = - if newline: writeLine(stdout, strings.foldl(a & b)) - else: write(stdout, strings.foldl(a & b)) + if newline: writeLine(stdout, strings.foldl(a & " " & b)) + else: write(stdout, strings.foldl(a & " " & b)) flushFile(stdout) dispatch(main, version=("version", nimbaseVersion)) diff --git a/head.nim b/head.nim index 24a72dc..a4b6c82 100644 --- a/head.nim +++ b/head.nim @@ -5,16 +5,17 @@ proc main(files:seq[string], lines=10, bytes=0) = # if files.len == 0: # files.add "-" for file in files: - var s = newFileStream(file, fmRead) + var f = if file == "-": stdin + else: open(file, fmRead) if bytes > 0: var currentByte = 0 - while not s.atEnd and currentByte < bytes: - write(stdout, s.readChar) + while not f.endOfFile and currentByte < bytes: + write(stdout, f.readChar) inc currentByte elif lines > 0: var currentLine = 0 - while not s.atEnd and currentLine < lines: - echo s.readLine + while not f.endOfFile and currentLine < lines: + writeLine(stdout, f.readLine) inc currentLine dispatch(main, version=("version", nimbaseVersion)) diff --git a/nimbase.nimble b/nimbase.nimble index 929969b..1b02f79 100644 --- a/nimbase.nimble +++ b/nimbase.nimble @@ -8,6 +8,6 @@ requires "nim >= 0.19.0" requires "cligen >= 0.9.19" requires "stint >= 0.0.1" -bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "pwd", "rm", "seq", "sleep", "sub", "tee", "touch", "true", "yes"] +bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "pwd", "rm", "seq", "shuf", "sleep", "sub", "tee", "touch", "true", "yes"] binDir = "bin" diff --git a/rev.nim b/rev.nim new file mode 100644 index 0000000..e69de29 diff --git a/rm.nim b/rm.nim index 671629d..6022cf5 100644 --- a/rm.nim +++ b/rm.nim @@ -12,10 +12,10 @@ proc main(files:seq[string], force=false, recursive=false) = if recursive: removeDir(file) else: - echo errorMsg & file & "': Is a directory" + err errorMsg & file & "': Is a directory" programResult = 1 else: - echo errorMsg & file & "': No such file or directory" + err errorMsg & file & "': No such file or directory" programResult = 1 dispatch(main, version=("version", nimbaseVersion)) diff --git a/shuf.nim b/shuf.nim new file mode 100644 index 0000000..9450259 --- /dev/null +++ b/shuf.nim @@ -0,0 +1,8 @@ +import cligen +import common + +proc main(files:seq[string]) = + for file in files: + echo "" + +dispatch(main, version=("version", nimbaseVersion)) diff --git a/tac.nim b/tac.nim new file mode 100644 index 0000000..e69de29