Skip to content

Usage Examples

Adrian Thomas edited this page Sep 30, 2025 · 6 revisions

Usage Examples & Workflows

This page provides comprehensive examples of how to use symlinkit effectively across different scenarios and workflows.

📋 Table of Contents


🎯 Basic Operations

Simple Symlink Creation

# Create a single symlink (overwrite mode) - operation flag required
symlinkit -o ~/dotfiles/.zshrc ~/.zshrc

# Create symlinks for directory contents (merge mode)
symlinkit -m ~/dotfiles/scripts ~/bin

# Preview before making changes
symlinkit --dry-run -o ~/dotfiles/nvim ~/.config/nvim

Symlink Deletion

# Delete a symlink safely
symlinkit -d ~/.config/nvim

# Preview deletion first (dry-run)
symlinkit --dry-run -d ~/.local/bin/old-script

# Delete with path verification
symlinkit -d /usr/local/bin/deprecated-tool
# → Shows: "Deleted: /usr/local/bin/deprecated-tool → /opt/tools/old-version"

Interactive Mode

# Interactive selection with explicit operation (required)
symlinkit -o
# → You'll be prompted to select source and destination

# Running without operation shows helpful error
symlinkit
# → Error: "No operation specified. Use -o (overwrite), -m (merge), or -d (delete)."
# → Lists all available operations and commands

🔗 Flag Chaining & Recursive Operations

Create Recursive (-cr)

Create symlinks recursively using intuitive flag chaining:

# Traditional merge mode
symlinkit -m ~/dotfiles/config ~/.config

# New flag chaining syntax (identical behavior)
symlinkit -cr ~/dotfiles/config ~/.config

# Both reverse orders work
symlinkit -rc ~/dotfiles/config ~/.config

Result:

~/.config/config/file1 → ~/dotfiles/config/file1
~/.config/config/file2 → ~/dotfiles/config/file2
~/.config/config/file3 → ~/dotfiles/config/file3

Overwrite Recursive (-or)

Recursively create symlinks with interactive conflict prompts:

# Overwrite mode with recursive linking
symlinkit -or ~/dotfiles/scripts ~/bin

Interactive prompts on conflicts:

⚠️ Conflict: /home/user/bin/scripts/deploy.sh exists.
[s]kip / [o]verwrite / [a]ll overwrite / [c]ancel > o
🔄 Overwriting: /home/user/bin/scripts/deploy.sh

⚠️ Conflict: /home/user/bin/scripts/backup.sh exists.
[s]kip / [o]verwrite / [a]ll overwrite / [c]ancel > a
🔄 Overwriting (all): /home/user/bin/scripts/backup.sh
🔄 Overwriting (all): /home/user/bin/scripts/restore.sh

Using [a]ll overwrite: Press [a] to automatically overwrite all remaining conflicts without more prompts.

Delete Recursive (-dr)

Interactively delete all symlinks in a directory:

# Delete multiple symlinks with confirmation
symlinkit -dr ~/.config

Output:

Found 5 symlink(s) in /home/user/.config
/home/user/.config/nvim → /home/user/dotfiles/nvim
[d]elete / [a]ll delete / [s]kip / [q]uit > d
❌ Deleted: /home/user/.config/nvim

/home/user/.config/fish → /home/user/dotfiles/fish
[d]elete / [a]ll delete / [s]kip / [q]uit > a
❌ Deleted (all): /home/user/.config/fish
❌ Deleted (all): /home/user/.config/alacritty
❌ Deleted (all): /home/user/.config/kitty

📊 Summary: 4 deleted, 0 skipped

Options explained:

  • [d]elete - Delete this symlink, prompt for next
  • [a]ll delete - Delete all remaining symlinks without prompts
  • [s]kip - Skip this symlink, keep it
  • [q]uit - Exit immediately

Dry-Run with Recursive Operations

Always preview recursive operations first:

# Preview recursive delete
symlinkit --dry-run -dr ~/test-links

Output:

Found 3 symlink(s) in /home/user/test-links
/home/user/test-links/link1 → /home/user/source/file1
[d]elete / [a]ll delete / [s]kip / [q]uit > a
❌ Would delete (all): /home/user/test-links/link1
❌ Would delete (all): /home/user/test-links/link2
❌ Would delete (all): /home/user/test-links/link3
📊 Summary: 3 deleted, 0 skipped

(Dry run: no changes applied)

All symlinks remain intact after dry-run.

Real-World Examples

Cleanup Test Environment:

# Preview what would be deleted
symlinkit --dry-run -dr ~/test-env

# Delete all test symlinks
symlinkit -dr ~/test-env
# Press [a] on first prompt to delete all

Reorganize Configuration:

# Step 1: Remove old symlinks
symlinkit -dr ~/.config/old-setup

# Step 2: Create new symlinks recursively
symlinkit -cr ~/dotfiles/new-config ~/.config

Batch Config Update:

# Overwrite all existing configs with new versions
symlinkit -or ~/dotfiles/updated-config ~/.config
# Press [a] on first conflict to update all

Safe Migration Workflow:

# 1. Preview changes
symlinkit --dry-run -dr ~/.old-configs

# 2. Delete old symlinks
symlinkit -dr ~/.old-configs

# 3. Create new structure
symlinkit -cr ~/new-dotfiles ~/.config

# 4. Verify with tree view
symlinkit --tree ~/.config

🖱️ Interactive Selection Examples

With fzf (Enhanced Experience)

# Use fzf for interactive selection (default if fzf available)
symlinkit --list
# → Shows fuzzy-searchable directory list with preview

# Force fzf usage (error if not available)
symlinkit --fzf --broken
# → Ensures consistent fzf experience in scripts

Manual Prompts (Fallback)

# Force manual text input prompts
symlinkit --no-fzf --list
# → Shows: "Specify a directory to list symlinks: "
# → You type: ~/dotfiles

# Useful for minimal environments or scripts
symlinkit --no-fzf -o
# → "Specify source directory: " → ~/source
# → "Specify destination directory: " → ~/target

🏠 Dotfiles Management

Initial Setup

# Set up your entire dotfiles directory
cd ~/
symlinkit -m ~/dotfiles .
# → Merges all dotfiles into home directory

# Preview the operation first
symlinkit --dry-run -m ~/dotfiles .
# → Shows what would be linked without making changes

Selective Dotfile Linking

# Link specific config directories
symlinkit -o ~/dotfiles/.zshrc ~/.zshrc
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc
symlinkit -m ~/dotfiles/.config ~/.config

# With tree view to see results
symlinkit -o ~/dotfiles/tmux ~/.config/tmux --tree

Dotfile Maintenance

# Find broken dotfile links
symlinkit --broken ~
# → Shows any broken symlinks in home directory

# Interactive repair
symlinkit --fix-broken ~
# → For each broken link: [d]elete / [u]pdate / [s]kip

# Audit all dotfile symlinks
symlinkit --json --list ~ > dotfiles-audit.json

⚙️ System Administration

System-wide Symlink Management

# Audit system symlinks
symlinkit --list /usr/local/bin
symlinkit --broken /etc

# Count symlinks in various directories
symlinkit --count-only /usr/bin
symlinkit --count-only /opt

Service Configuration

# Link service configurations
symlinkit -o ~/configs/nginx.conf /etc/nginx/nginx.conf
symlinkit -m ~/configs/systemd /etc/systemd/system

# Preview system changes (recommended)
symlinkit --dry-run -m ~/configs/services /etc/systemd/system

Symlink Cleanup

# Remove deprecated symlinks
symlinkit -d /usr/local/bin/old-version
symlinkit -d /opt/legacy-tool

# Preview deletion before executing
symlinkit --dry-run -d /etc/deprecated-config

# Batch cleanup script
for link in /usr/local/bin/deprecated-*; do
  if [[ -L "$link" ]]; then
    echo "Removing: $link"
    symlinkit -d "$link"
  fi
done

Maintenance Scripts

#!/bin/bash
# Weekly symlink health check
echo "Checking for broken symlinks..."
symlinkit --broken / 2>/dev/null | tee broken-links-$(date +%Y%m%d).log

# Generate system symlink report
symlinkit --json --list /usr/local/bin > "system-symlinks-$(date +%Y%m%d).json"

💻 Development Workflows

Project Setup

# Link development tools
symlinkit -m ~/dev-tools/bin ~/bin

# Link project-specific configs
symlinkit -o ~/projects/myapp/.eslintrc ~/.eslintrc
symlinkit -o ~/projects/myapp/.prettierrc ~/.prettierrc

Multi-Environment Management

# Development environment
symlinkit -o ~/configs/dev/vimrc ~/.vimrc

# Production environment
symlinkit -o ~/configs/prod/vimrc ~/.vimrc

# Preview environment switch
symlinkit --dry-run -o ~/configs/staging/nginx.conf /etc/nginx/nginx.conf

Build Tool Integration

# Link build outputs
symlinkit -m ~/project/dist ~/public/assets

# With confirmation via tree view
symlinkit -m ~/project/dist ~/public/assets --tree-verbose

🔍 Inspection & Maintenance

Health Monitoring

# Regular health check
symlinkit --broken ~
symlinkit --broken /usr/local/bin
symlinkit --broken /opt

# Count-only for quick stats
symlinkit --count-only ~ && echo "symlinks in home"
symlinkit --count-only /usr/bin && echo "symlinks in /usr/bin"

Visual Inspection

# Tree view of symlinks only
symlinkit --tree ~/.config
symlinkit --tree /usr/local/bin

# Detailed tree with permissions
symlinkit --tree-verbose ~/.config

Interactive Repair Workflows

# Fix broken links with guided prompts
symlinkit --fix-broken ~
# For each broken link:
# [d]elete → Remove the broken symlink
# [u]pdate → Point to a new target (with optional fzf picker)
# [s]kip   → Leave unchanged

# Limit search depth for performance
symlinkit --depth 2 --fix-broken ~/projects

📊 JSON Output & Scripting

Basic JSON Operations

# List all symlinks as JSON
symlinkit --json --list ~

# Find broken symlinks as JSON
symlinkit --json --broken /usr/local/bin

# Count symlinks with metadata
symlinkit --json --count-only ~/.config

Scripting Examples

#!/bin/bash
# Automated symlink audit script

# Generate comprehensive report
{
  echo "{"
  echo "  \"timestamp\": \"$(date -Iseconds)\","
  echo "  \"hostname\": \"$(hostname)\","
  echo "  \"home_symlinks\": $(symlinkit --json --list ~),"
  echo "  \"broken_symlinks\": $(symlinkit --json --broken ~),"
  echo "  \"usr_local_bin\": $(symlinkit --json --count-only /usr/local/bin)"
  echo "}"
} > symlink-report-$(date +%Y%m%d).json

# Process with jq if available
if command -v jq >/dev/null 2>&1; then
  cat symlink-report-*.json | jq '.broken_symlinks | length'
  echo "broken symlinks found"
fi

Integration with Other Tools

# Export to CSV (with jq)
symlinkit --json --list ~ | jq -r '.[] | [.path, .target] | @csv' > symlinks.csv

# Filter specific patterns
symlinkit --json --list ~/.config | jq '.[] | select(.target | contains("dotfiles"))'

# Count by target directory
symlinkit --json --list ~ | jq 'group_by(.target | split("/")[1:2] | join("/")) | map({target: .[0].target | split("/")[1:2] | join("/"), count: length})'

🚀 Advanced Scenarios

Complex Directory Structures

# Multi-level directory linking with depth control
symlinkit --depth 5 --tree ~/complex-project

# Selective depth for performance
symlinkit --depth 1 --fix-broken /large-directory

Sorting and Organization

# Sort by symlink path
symlinkit --sort path --list ~/.config

# Sort by target location
symlinkit --sort target --list ~/bin

Batch Operations with Preview

# Preview multiple operations
symlinkit --dry-run -m ~/dotfiles/config ~/.config
symlinkit --dry-run -m ~/dotfiles/local ~/.local

# Apply after review
symlinkit -m ~/dotfiles/config ~/.config
symlinkit -m ~/dotfiles/local ~/.local

Error Handling in Scripts

#!/bin/bash
set -euo pipefail

# Robust script with error handling
if symlinkit --json --broken ~ | jq -e '. | length > 0' >/dev/null; then
  echo "⚠️  Broken symlinks detected!"
  symlinkit --broken ~

  read -p "Fix broken symlinks interactively? (y/N): " -n 1 -r
  echo
  if [[ $REPLY =~ ^[Yy]$ ]]; then
    symlinkit --fix-broken ~
  fi
else
  echo "✅ No broken symlinks found"
fi

🎯 Best Practices

Safety First

# Always preview significant changes
symlinkit --dry-run -m ~/dotfiles ~/.config

# Use depth limits for large directories
symlinkit --depth 3 --list /usr

# Keep backups before major linking operations
cp -r ~/.config ~/.config.backup
symlinkit -m ~/dotfiles/config ~/.config

Performance Optimization

# Limit depth for faster operations
symlinkit --depth 2 --broken /

# Use count-only for quick statistics
symlinkit --count-only /usr/bin

# Target specific directories instead of root
symlinkit --list /usr/local/bin  # Fast
symlinkit --list /                # Slow

Maintenance Automation

# Weekly cron job for symlink health
0 9 * * 1 symlinkit --broken ~ | mail -s "Weekly Symlink Report" admin@example.com

# Monthly audit with JSON logging
0 0 1 * * symlinkit --json --list ~ > ~/logs/symlinks-$(date +\%Y\%m).json

🔧 Troubleshooting Common Scenarios

Permission Issues

# Check permissions before linking
ls -la ~/dotfiles/config
symlinkit --dry-run -o ~/dotfiles/config ~/.config

# Use tree-verbose to see permissions
symlinkit --tree-verbose ~/.config

Path Resolution Issues

# Verify paths are resolved correctly
symlinkit --list ~/.config | head -5

# Check for absolute vs relative targets
symlinkit --json --list ~/.config | jq '.[] | select(.target | startswith("/") | not)'

fzf Availability Issues

# Test fzf availability
symlinkit --fzf --version  # Errors if fzf missing

# Force manual mode
symlinkit --no-fzf --list  # Always works

# Check current mode
command -v fzf && echo "fzf available" || echo "fzf not available"

Need more examples? Check the Contributing page to suggest new use cases or contribute your own examples!

Symlinkit Wiki Navigation

Getting Started

Features & Functionality

Development & Contributing

Clone this wiki locally