Skip to content

Commit

Permalink
fix bug with relative links not located in cwd, make broken links les…
Browse files Browse the repository at this point in the history
…s gaudy looking, and add broken link icon
  • Loading branch information
Andrew Carlson committed May 16, 2020
1 parent e3e6be4 commit 2cfde87
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ var (
"name": Bold + FgRGB(0, 5, 0),
"arrow": FgRGB(1, 0, 1),
"path": FgRGB(4, 0, 4),
"broken": BgRGB(5, 0, 0) + FgRGB(5, 5, 0),
"broken": FgRGB(5, 0, 0),
},
"device": map[string]string{
"name": Bold + BgGray(3) + Fg(220),
Expand Down
5 changes: 3 additions & 2 deletions file-icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ var folders = map[string]string{
}

var otherIcons = map[string]string{
"link": "\uf0c1",
"device": "\uf0a0",
"link": "\uf0c1",
"brokenLink": "\uf127",
"device": "\uf0a0",
}
21 changes: 17 additions & 4 deletions ls-go.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ func getLinkInfo(item *DisplayItem, absPath string) {
fullPath := path.Join(absPath, item.info.Name())
linkPath, err1 := os.Readlink(fullPath)
check(err1)
linkInfo, err2 := os.Stat(linkPath)

linkFullPath := linkPath
if linkPath[0] == '.' {
linkFullPath = path.Join(absPath, linkPath)
}

linkInfo, err2 := os.Stat(linkFullPath)
if *args.linkRel {
linkRel, _ := filepath.Rel(absPath, linkPath)
if linkRel != "" && len(linkRel) <= len(linkPath) {
Expand All @@ -284,6 +290,7 @@ func getLinkInfo(item *DisplayItem, absPath string) {
}
}
}

link := LinkInfo{
path: linkPath,
}
Expand All @@ -305,11 +312,17 @@ func nameString(item *DisplayItem) string {
} else if mode&os.ModeSymlink != 0 {
color := ConfigColor["link"]["name"]
if *args.nerdfont {
return color + otherIcons["link"] + " " + name + " " + Reset
var linkIcon string
if item.link.broken {
linkIcon = otherIcons["brokenLink"]
} else {
linkIcon = otherIcons["link"]
}
return color + linkIcon + " " + name + " " + Reset
} else if *args.icons {
return color + "🔗 " + name + " " + Reset
} else {
return color + " " + name + " " + Reset
return color + name + " " + Reset
}
} else if mode&os.ModeDevice != 0 {
color := ConfigColor["device"]["name"]
Expand All @@ -318,7 +331,7 @@ func nameString(item *DisplayItem) string {
} else if *args.icons {
return color + "💽 " + name + " " + Reset
} else {
return color + " " + name + " " + Reset
return color + name + " " + Reset
}
} else if mode&os.ModeNamedPipe != 0 {
return ConfigColor["pipe"]["name"] + " " + name + " " + Reset
Expand Down

0 comments on commit 2cfde87

Please sign in to comment.