head utility works
This commit is contained in:
parent
54ccd5fc9a
commit
3866bec55e
1 changed files with 11 additions and 3 deletions
14
head.nim
14
head.nim
|
|
@ -1,10 +1,18 @@
|
||||||
import cligen, os, streams
|
import cligen, os, streams
|
||||||
import common
|
import common
|
||||||
|
|
||||||
proc main(files:seq[string]) =
|
proc main(files:seq[string], lines=10, bytes=0) =
|
||||||
for file in files:
|
for file in files:
|
||||||
var s = newFileStream(file, fmRead)
|
var s = newFileStream(file, fmRead)
|
||||||
while not s.atEnd:
|
if bytes > 0:
|
||||||
write(stdout, s.readChar)
|
var currentByte = 0
|
||||||
|
while not s.atEnd and currentByte < bytes:
|
||||||
|
write(stdout, s.readChar)
|
||||||
|
inc currentByte
|
||||||
|
elif lines > 0:
|
||||||
|
var currentLine = 0
|
||||||
|
while not s.atEnd and currentLine < lines:
|
||||||
|
echo s.readLine
|
||||||
|
inc currentLine
|
||||||
|
|
||||||
dispatch(main, version=("version", nimbaseVersion))
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue