mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-07 17:43:53 +02:00
More work on the transfer kitten
This commit is contained in:
@@ -30,6 +30,8 @@ func Reversed[T any](s []T) []T {
|
||||
func Remove[T comparable](s []T, q T) []T {
|
||||
idx := slices.Index(s, q)
|
||||
if idx > -1 {
|
||||
var zero T
|
||||
s[idx] = zero // if pointer this allows garbage collection
|
||||
return slices.Delete(s, idx, idx+1)
|
||||
}
|
||||
return s
|
||||
|
||||
@@ -13,8 +13,10 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -291,3 +293,29 @@ func ResolveConfPath(path string) string {
|
||||
}
|
||||
return cs
|
||||
}
|
||||
|
||||
// Longest common path. Must be passed paths that have been cleaned by filepath.Clean
|
||||
func Commonpath(paths ...string) (longest_prefix string) {
|
||||
switch len(paths) {
|
||||
case 0:
|
||||
return
|
||||
case 1:
|
||||
return paths[0]
|
||||
default:
|
||||
sort.Strings(paths)
|
||||
a, b := paths[0], paths[len(paths)-1]
|
||||
sz := 0
|
||||
for a != "" && b != "" {
|
||||
ra, na := utf8.DecodeRuneInString(a)
|
||||
rb, nb := utf8.DecodeRuneInString(b)
|
||||
if ra != rb {
|
||||
break
|
||||
}
|
||||
sz += na
|
||||
a = a[na:]
|
||||
b = b[nb:]
|
||||
}
|
||||
longest_prefix = a[:sz]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user