fork/gdu

git clone https://git.julia.blue/fork/gdu

Kian-Meng Angdocs: fix typos (#397)c67b451

ignore
509 B26 linesraw
1package path
2
3import "strings"
4
5// ShortenPath removes the last but one path components to fit into maxLen
6func ShortenPath(path string, maxLen int) string {
7	if len(path) <= maxLen {
8		return path
9	}
10
11	res := ""
12	parts := strings.SplitAfter(path, "/")
13	curLen := len(parts[len(parts)-1]) // count length of last part for start
14
15	for _, part := range parts[:len(parts)-1] {
16		curLen += len(part)
17		if curLen > maxLen {
18			res += ".../"
19			break
20		}
21		res += part
22	}
23
24	res += parts[len(parts)-1]
25	return res
26}