1
0
mirror of https://github.com/thebaer/tildes.git synced 2018-07-20 07:15:21 +00:00

Indicate directories and executable files

Directories get slash appended and color coding
Other-executable files get color coding
This commit is contained in:
Matt Baer 2015-02-09 23:30:24 -05:00
parent 968dcb54da
commit b745d5c627
2 changed files with 32 additions and 3 deletions

19
code.go
View File

@ -38,6 +38,7 @@ type User struct {
type Project struct { type Project struct {
Name string Name string
Path string Path string
CssClass string
} }
func findProjects() map[string]User { func findProjects() map[string]User {
@ -72,11 +73,25 @@ func mapFiles(files *[]string, users map[string]User) {
// Ensure file is other-readable // Ensure file is other-readable
// TODO: just detect if we can actually read this, instead // TODO: just detect if we can actually read this, instead
info, _ := os.Stat(path) info, _ := os.Stat(path)
if info.Mode() & 0004 == 0 { mode := info.Mode()
if mode & 0004 == 0 {
continue 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] u, exists := users[uname]
if !exists { if !exists {
fmt.Printf("Found %s for ~%s.\n", pparts[3], uname) fmt.Printf("Found %s for ~%s.\n", pparts[3], uname)

View File

@ -5,6 +5,20 @@
<title>{{.FolderName}} on {{.Host}}</title> <title>{{.FolderName}} on {{.Host}}</title>
<link type="text/css" rel="stylesheet" href="tilde.css" /> <link type="text/css" rel="stylesheet" href="tilde.css" />
<style type="text/css">
.dir {
font-weight: bold;
color: #00BFFF;
}
.file.exec {
font-weight: bold;
color: #FFD700;
}
.fullDir {
color: #aaa;
font-size: 0.9em;
}
</style>
</head> </head>
<body id="hello"> <body id="hello">
@ -17,7 +31,7 @@
<div class="links"> <div class="links">
<ul class="links"> <ul class="links">
{{range .Projects}} {{range .Projects}}
<li><strong>{{.Name}}</strong> &middot; {{.Path}}</li> <li><span class="{{.CssClass}}">{{.Name}}</span> <span class="fullDir">&middot; {{.Path}}</span></li>
{{end}} {{end}}
</ul> </ul>
</div> </div>