Skip to content

Commit

Permalink
recursively looking for files in newFileTable
Browse files Browse the repository at this point in the history
also normalizing name to lowercase so its easier to access keys in it
as search can be normalized to lowecase

chalk will be using that in upcoming PR related to the help system
  • Loading branch information
miki725 committed Feb 1, 2024
1 parent 516dc45 commit fc56a53
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nimutils/filetable.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ proc staticListFiles*(arg: string): seq[string] =
result = @[]

let
lines = staticExec("ls --color=never -pF " & arg &
" | grep -v \"[^a-zA-Z0-9]$\"")
lines = staticExec("find " & arg & " -type f " &
" | grep -v \"[^a-zA-Z0-9]$\"")
items = split(lines, "\n")

for item in items:
result.add(item.strip())
var path = item
path.removePrefix(arg)
path.removePrefix(DirSep)
result.add(path.strip())


template newFileTable*(dir: static[string]): FileTable =
Expand All @@ -55,7 +58,7 @@ template newFileTable*(dir: static[string]): FileTable =
let
pathToFile = pwd.joinPath(filename)
fileContents = staticRead(pathToFile)
key = splitFile(filename).name
key = splitFile(filename).name.toLower()

ret[key] = fileContents
ret
Expand Down

0 comments on commit fc56a53

Please sign in to comment.