~mkhl/xplor

0a30c8fb91d57d3d9c4b7fec19406e966cd5631e — Martin Kühl 10 months ago 3b3af59
Simplify path splitting
1 files changed, 5 insertions(+), 12 deletions(-)

M xplor.go
M xplor.go => xplor.go +5 -12
@@ 244,10 244,6 @@ func print(addr string) error {
// Selection

func selectEntry(path string) error {
	path, err := filepath.Rel(root, path)
	if err != nil {
		return err
	}
	var steps strings.Builder
	steps.WriteString("0") // beginning
	for depth, name := range split(path) {


@@ 319,14 315,11 @@ func abspath(addr string) (string, int, error) {

// Determine components of path
func split(path string) []string {
	var part string
	parts := make([]string, 0)
	for path != "" && path != "." {
		path, part = filepath.Split(path)
		path = filepath.Clean(path)
		parts = append([]string{part}, parts...)
	}
	return parts
	if path == root {
		return []string{}
	}
	path = strings.TrimPrefix(path, root + "/")
	return strings.Split(path, string(filepath.Separator))
}

// System Interaction