Skip to content

Commit 1febdf8

Browse files
committed
Capture node uid and gid.
1 parent 18df8b9 commit 1febdf8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

node/root.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package node
33
import (
44
"os"
55
"fmt"
6+
"syscall"
7+
"os/user"
68
"github.com/fatih/color"
79
"github.com/drn/nerd-ls/icon"
810
)
@@ -13,14 +15,30 @@ type Node struct {
1315
Length int
1416
Mode string
1517
Size int
18+
User string
19+
Group string
1620
}
1721

1822
// New - Initializes Node with os.FileInfo
1923
func New(file os.FileInfo) Node {
2024
name := rawName(file)
2125
length := len([]rune(name))
2226
name = colorize(file, name)
23-
return Node{name, length, file.Mode().String(), int(file.Size())}
27+
28+
uid := fmt.Sprint(file.Sys().(*syscall.Stat_t).Uid)
29+
gid := fmt.Sprint(file.Sys().(*syscall.Stat_t).Gid)
30+
31+
fileUser, _ := user.LookupId(uid)
32+
fileGroup, _ := user.LookupGroupId(gid)
33+
34+
return Node{
35+
name,
36+
length,
37+
file.Mode().String(),
38+
int(file.Size()),
39+
fileUser.Username,
40+
fileGroup.Name,
41+
}
2442
}
2543

2644
func rawName(file os.FileInfo) string {

0 commit comments

Comments
 (0)