From b745d5c6275b67d4fbb55f458cd12271e395eecf Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 9 Feb 2015 23:30:24 -0500 Subject: [PATCH] Indicate directories and executable files Directories get slash appended and color coding Other-executable files get color coding --- code.go | 19 +++++++++++++++++-- templates/code.html | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/code.go b/code.go index 3c4982a..ffe5782 100644 --- a/code.go +++ b/code.go @@ -38,6 +38,7 @@ type User struct { type Project struct { Name string Path string + CssClass string } func findProjects() map[string]User { @@ -72,11 +73,25 @@ func mapFiles(files *[]string, users map[string]User) { // Ensure file is other-readable // TODO: just detect if we can actually read this, instead info, _ := os.Stat(path) - if info.Mode() & 0004 == 0 { + mode := info.Mode() + if mode & 0004 == 0 { continue } - proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1)} + // Mark directories vs. regular files + cssClass := "file" + if mode.IsDir() { + path = path + "/" + fname = fname + "/" + cssClass = "dir" + } + + // Check if files are executable by all + if mode & 0001 != 0 { + cssClass = cssClass + " exec" + } + + proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1), CssClass: cssClass} u, exists := users[uname] if !exists { fmt.Printf("Found %s for ~%s.\n", pparts[3], uname) diff --git a/templates/code.html b/templates/code.html index f257819..2f763db 100644 --- a/templates/code.html +++ b/templates/code.html @@ -5,6 +5,20 @@ {{.FolderName}} on {{.Host}} + @@ -17,7 +31,7 @@