fork/gdu
git clone https://git.julia.blue/fork/gdu
c67b451
ignore
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 { 7if len (path )<= maxLen { 8return path 9 } 10 11res := "" 12parts := strings .SplitAfter (path ,"/" ) 13curLen := len (parts [len (parts )- 1 ])// count length of last part for start 14 15for _ ,part := range parts [:len (parts )- 1 ] { 16curLen += len (part ) 17if curLen > maxLen { 18res += ".../" 19break 20 } 21res += part 22 } 23 24res += parts [len (parts )- 1 ] 25return res 26}