feat: improve init flow with explicit target selection

- Only auto-add target when user copies from it
- Ask user before adding other detected targets
- Detect CLI tools with parent directory (not initialized)
- Add "Sync Across Machines" section to README
This commit is contained in:
Willie
2026-01-14 20:59:34 +08:00
parent 95ca07be89
commit 3a4bc02244
2 changed files with 160 additions and 26 deletions
+108 -15
View File
@@ -30,7 +30,7 @@ Keeping them in sync manually is tedious.
~/.claude/skills/
├── my-skill -> ~/.config/skillshare/skills/my-skill (symlink)
├── another-skill -> ~/.config/skillshare/skills/another-skill (symlink)
└── local-only/ <- Local skills are preserved
└── local-only/ <- Local skills are preserved (merge mode)
```
## Installation
@@ -39,11 +39,11 @@ Keeping them in sync manually is tedious.
```bash
# Apple Silicon (M1/M2/M3/M4)
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_0.1.0_darwin_arm64.tar.gz | tar xz
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_darwin_arm64.tar.gz | tar xz
sudo mv skillshare /usr/local/bin/
# Intel
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_0.1.0_darwin_amd64.tar.gz | tar xz
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_darwin_amd64.tar.gz | tar xz
sudo mv skillshare /usr/local/bin/
```
@@ -51,11 +51,11 @@ sudo mv skillshare /usr/local/bin/
```bash
# x86_64
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_0.1.0_linux_amd64.tar.gz | tar xz
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_linux_amd64.tar.gz | tar xz
sudo mv skillshare /usr/local/bin/
# ARM64
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_0.1.0_linux_arm64.tar.gz | tar xz
curl -sL https://github.com/runkids/skillshare/releases/latest/download/skillshare_linux_arm64.tar.gz | tar xz
sudo mv skillshare /usr/local/bin/
```
@@ -91,7 +91,7 @@ rm -rf ~/.config/skillshare
## Quick Start
```bash
# 1. Initialize with default source directory (~/.skills)
# 1. Initialize (interactive source selection)
skillshare init
# 2. Check detected targets
@@ -106,7 +106,7 @@ skillshare sync
### Initialize
```bash
# Use default source (~/.skills)
# Interactive mode - choose source from existing skills directories
skillshare init
# Or specify custom source
@@ -116,6 +116,7 @@ skillshare init --source ~/my-skills
This will:
- Create the source directory
- Detect installed CLI tools
- Optionally copy skills from existing directories
- Create config at `~/.config/skillshare/config.yaml`
### Sync
@@ -138,14 +139,53 @@ skillshare status
Shows:
- Source directory and skill count
- Each target's status (linked, has files, not exist, conflict)
- Each target's status, mode, and sync state
### Diff
```bash
# Show differences for all targets
skillshare diff
# Show differences for specific target
skillshare diff claude
```
### Backup
```bash
# Backup all targets
skillshare backup
# Backup specific target
skillshare backup claude
```
### Doctor
```bash
skillshare doctor
```
Diagnoses:
- Config file status
- Source directory
- Symlink support
- Each target's health and mode
### Manage Targets
```bash
# List targets
# List all targets
skillshare target list
# Show target info
skillshare target claude
# Change target sync mode
skillshare target claude --mode merge
skillshare target claude --mode symlink
# Add custom target
skillshare target add myapp ~/.myapp/skills
@@ -166,9 +206,9 @@ mode: merge # default mode for all targets
targets:
claude:
path: ~/.claude/skills
mode: symlink # override: use full directory symlink
codex:
path: ~/.codex/skills
mode: symlink # override: use full directory symlink
cursor:
path: ~/.cursor/skills
gemini:
@@ -189,14 +229,67 @@ ignore:
Use `symlink` mode when you want all targets to share exactly the same skills.
Change mode per target:
```bash
skillshare target claude --mode symlink
skillshare sync
```
## How It Works
1. **init**: Detects CLI tools, optionally copy from existing skills
2. **sync**:
- Backup targets with local skills before sync
- Create symlinks (merge mode: per-skill, symlink mode: whole directory)
3. **status**: Check symlink health
4. **target remove**: Backup, unlink symlinks, restore skills
2. **sync**: Create symlinks (merge mode: per-skill, symlink mode: whole directory)
3. **status**: Check symlink health and mode
4. **diff**: Show differences between source and targets
5. **backup**: Create manual backup of targets
6. **doctor**: Diagnose configuration issues
7. **target remove**: Backup, unlink symlinks, restore skills
## Sync Across Machines
Use git to sync your skills across multiple machines:
### Initial Setup (Machine A)
```bash
# Initialize skillshare
skillshare init
# Push skills to remote
cd ~/.config/skillshare/skills
git init
git add .
git commit -m "Initial skills"
git remote add origin git@github.com:you/my-skills.git
git push -u origin main
```
### Clone to Another Machine (Machine B)
```bash
# Clone your skills repo
git clone git@github.com:you/my-skills.git ~/.config/skillshare/skills
# Initialize skillshare with the cloned source
skillshare init --source ~/.config/skillshare/skills
# Sync to all targets
skillshare sync
```
### Daily Workflow
```bash
# Machine A - add/update skills
cd ~/.config/skillshare/skills
# ... edit skills ...
git add . && git commit -m "Update skills" && git push
# Machine B - pull and sync
cd ~/.config/skillshare/skills
git pull
skillshare sync # New skills are automatically symlinked
```
## Backups
+52 -11
View File
@@ -120,12 +120,13 @@ func cmdInit(args []string) error {
path string
skillCount int
hasSkills bool
exists bool // true if skills dir exists, false if only parent exists
}
var detected []detectedDir
for name, target := range defaultTargets {
if info, err := os.Stat(target.Path); err == nil && info.IsDir() {
// Count skills
// Skills directory exists - count skills
entries, _ := os.ReadDir(target.Path)
skillCount := 0
for _, e := range entries {
@@ -138,12 +139,26 @@ func cmdInit(args []string) error {
path: target.Path,
skillCount: skillCount,
hasSkills: skillCount > 0,
exists: true,
})
if skillCount > 0 {
ui.Success("Found: %s (%d skills)", name, skillCount)
} else {
ui.Info("Found: %s (empty)", name)
}
} else {
// Skills directory doesn't exist - check if parent exists (CLI installed)
parent := filepath.Dir(target.Path)
if _, err := os.Stat(parent); err == nil {
detected = append(detected, detectedDir{
name: name,
path: target.Path,
skillCount: 0,
hasSkills: false,
exists: false,
})
ui.Info("Found: %s (not initialized)", name)
}
}
}
@@ -162,6 +177,7 @@ func cmdInit(args []string) error {
// Ask user if they want to initialize from existing skills
var copyFrom string
var copyFromName string
if len(withSkills) > 0 {
ui.Header("Initialize from existing skills?")
fmt.Println(" Copy skills from an existing directory to the shared source?")
@@ -184,7 +200,8 @@ func cmdInit(args []string) error {
if choice >= 1 && choice <= len(withSkills) {
copyFrom = withSkills[choice-1].path
ui.Success("Will copy skills from %s", withSkills[choice-1].name)
copyFromName = withSkills[choice-1].name
ui.Success("Will copy skills from %s", copyFromName)
} else {
ui.Info("Starting with empty source")
}
@@ -222,17 +239,41 @@ func cmdInit(args []string) error {
ui.Success("Copied %d skills to source", copied)
}
// Build targets list
// Build targets list - only add the directory user chose to copy from
targets := make(map[string]config.TargetConfig)
for name, target := range defaultTargets {
// Check if CLI is installed
if _, err := os.Stat(target.Path); err == nil {
targets[name] = target
} else {
parent := filepath.Dir(target.Path)
if _, err := os.Stat(parent); err == nil {
targets[name] = target
if copyFromName != "" {
targets[copyFromName] = config.TargetConfig{Path: copyFrom}
}
// Find other available targets (detected directories)
var otherTargets []string
for _, d := range detected {
if d.name == copyFromName {
continue // Already added
}
otherTargets = append(otherTargets, d.name)
}
// Ask if user wants to add other targets
if len(otherTargets) > 0 {
ui.Header("Add other CLI targets?")
fmt.Println(" Other CLI tools detected on your system:")
for _, name := range otherTargets {
fmt.Printf(" - %s\n", name)
}
fmt.Println()
fmt.Print(" Add these targets? [Y/n]: ")
var input string
fmt.Scanln(&input)
input = strings.ToLower(strings.TrimSpace(input))
if input == "" || input == "y" || input == "yes" {
for _, name := range otherTargets {
targets[name] = defaultTargets[name]
}
ui.Success("Added %d additional targets", len(otherTargets))
} else {
ui.Info("Skipped additional targets")
}
}