Files
skillshare/internal/utils/strings.go
T
Willie Hung fd4387460a feat: Team Edition - tracked repos, nested skills, collision detection
## New Features
- Tracked repositories: `install --track` to clone team skill repos
- Nested skills: organize in folders, auto-flatten on sync (work/api → work__api)
- Name collision detection: warns when multiple skills share same SKILL.md name
- Auto-pruning: orphaned symlinks cleaned on sync
- Custom naming: `--name` flag for tracked repos

## Changes
- Require target path to exist when adding targets
- Add sync reminder after adding target
- Improve pruning messages (broken vs orphan symlinks)
- Add `{team}:{name}` naming convention recommendation

## Files
- New: update.go, gitignore.go, frontmatter.go
- Updated: sync.go, install.go, uninstall.go, validate.go
- Docs: README.md, SKILL.md
2026-01-20 01:56:07 +08:00

64 lines
2.1 KiB
Go

package utils
import "strings"
// NestedSeparator is the separator used in flat names for nested paths.
// Example: "_team/frontend/ui" becomes "_team__frontend__ui"
const NestedSeparator = "__"
// TrackedRepoPrefix marks directories as tracked repositories.
// Directories starting with _ are cloned repos that preserve .git
const TrackedRepoPrefix = "_"
// IsHidden checks if a file/directory name starts with a dot.
// Returns false for empty strings to prevent panic on empty names.
func IsHidden(name string) bool {
return len(name) > 0 && name[0] == '.'
}
// HasTildePrefix checks if a path starts with ~.
// Returns false for empty strings to prevent panic on empty paths.
func HasTildePrefix(path string) bool {
return len(path) > 0 && path[0] == '~'
}
// PathToFlatName converts a relative path to a flat name using __ as separator.
// Example: "_team/frontend/ui" -> "_team__frontend__ui"
// Example: "my-skill" -> "my-skill" (no change for flat paths)
func PathToFlatName(relPath string) string {
// Normalize path separators and remove leading/trailing slashes
relPath = strings.ReplaceAll(relPath, "\\", "/")
relPath = strings.Trim(relPath, "/")
if relPath == "" || relPath == "." {
return ""
}
// Replace / with __
return strings.ReplaceAll(relPath, "/", NestedSeparator)
}
// FlatNameToPath converts a flat name back to a relative path.
// Example: "_team__frontend__ui" -> "_team/frontend/ui"
// Example: "my-skill" -> "my-skill" (no change for flat names)
func FlatNameToPath(flatName string) string {
if flatName == "" {
return ""
}
// Replace __ with /
return strings.ReplaceAll(flatName, NestedSeparator, "/")
}
// IsTrackedRepoDir checks if a directory name indicates a tracked repository.
// Tracked repos start with _ and contain .git directory.
func IsTrackedRepoDir(name string) bool {
return len(name) > 0 && name[0] == '_'
}
// HasNestedSeparator checks if a name contains the nested separator (__).
// This indicates the name came from a nested path structure.
func HasNestedSeparator(name string) bool {
return strings.Contains(name, NestedSeparator)
}