-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.nim
More file actions
70 lines (55 loc) · 1.71 KB
/
index.nim
File metadata and controls
70 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Dependencies
import osproc, strutils, tables, algorithm
# Variables
type
Node = ref object
name: string
children: Table[string, Node]
# Functions
proc newNode(name: string): Node =
result = Node(name: name, children: initTable[string, Node]())
proc printNode(node: Node, depth: int ) =
# Variables
var keys: seq[string] = @[]
# Core
for k in node.children.keys:
keys.add(k)
keys.sort()
for k in keys:
var child = node.children[k]
var isDir = child.children.len > 0
var symbol = if isDir: "\x1b[34m▼\x1b[0m" else: "\x1b[32m↳\x1b[0m"
var nameStr = if isDir: "\x1b[36m" & child.name & "\x1b[0m" else: child.name
if depth > 0 or node.name != "":
var indent = repeat(" ", depth)
echo indent, symbol, " ", nameStr
else:
echo symbol, " ", nameStr
printNode(child, depth + 1)
# Main
proc main() =
# Variables
var (outp, status) = execCmdEx("git diff --name-only")
# Validations
if status != 0:
echo "No repository found or no diff found."
return
# Core
var lines = outp.strip().splitLines()
var files: seq[string] = @[]
for line in lines:
var trimmed = line.strip()
if trimmed.len > 0:
files.add(trimmed)
if files.len == 0:
echo "No repository found or no diff found."
return
for file in files:
var parts = file.split("/")
var curr = root
for part in parts:
if not curr.children.hasKey(part):
curr.children[part] = newNode(part)
curr = curr.children[part]
printNode(root, 0)
main()