Skip to content

Usage Examples

Adrian Thomas edited this page Oct 2, 2025 · 6 revisions

Usage Examples & Workflows

Comprehensive examples of symlinkit 2.0 across different scenarios and workflows.


Basic Operations

Create a Single Symlink

# Link a config file
symlinkit -c ~/dotfiles/.bashrc ~/.bashrc

# Link a directory
symlinkit -c ~/dotfiles/nvim ~/.config/nvim

# Preview first
symlinkit --dry-run -c ~/dotfiles/.zshrc ~/.zshrc

Overwrite Existing File

# Replace existing file with symlink
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc

# Replace directory
symlinkit -o ~/dotfiles/scripts ~/bin

# Always preview first!
symlinkit --dry-run -o ~/source ~/dest

Merge Directories

# Merge dotfiles into home config
symlinkit -m ~/dotfiles/.config ~/.config

# Merge scripts into bin
symlinkit -m ~/dotfiles/scripts ~/bin

# Preview all changes
symlinkit --dry-run -m ~/dotfiles ~/.config

Delete Symlinks

# Delete single symlink
symlinkit -d ~/.config/nvim

# Delete all symlinks in directory
symlinkit -dr ~/bin

# Preview deletions
symlinkit --dry-run -d ~/.bashrc

Recursive Operations

Recursive Create (Merge)

# These are equivalent
symlinkit -cr ~/dotfiles ~/.config
symlinkit -m ~/dotfiles ~/.config

Recursive Overwrite

# Overwrite recursively with prompts
symlinkit -or ~/dotfiles/configs ~/.config

# For each conflict, you'll be prompted:
# [s]kip / [o]verwrite / [a]ll overwrite / [c]ancel >

Recursive Delete

# Delete all symlinks in directory
symlinkit -dr ~/old-links

# Interactive prompts for each symlink:
# [d]elete / [a]ll delete / [s]kip / [q]uit >

Dotfiles Management

Initial Setup

# Link shell configs
symlinkit -o ~/dotfiles/.bashrc ~/.bashrc
symlinkit -o ~/dotfiles/.zshrc ~/.zshrc
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc

# Link config directories
symlinkit -m ~/dotfiles/.config ~/.config

Gradual Migration

# Start with preview
symlinkit --dry-run -m ~/dotfiles/.config ~/.config

# Review output, then apply
symlinkit -m ~/dotfiles/.config ~/.config

# Handle conflicts interactively
# [s]kip / [o]verwrite / [a]ll overwrite / [c]ancel >

Complete Dotfiles Setup

#!/bin/bash
# dotfiles-setup.sh

DOTFILES="$HOME/dotfiles"

# Link shell configs
symlinkit -o "$DOTFILES/.bashrc" "$HOME/.bashrc"
symlinkit -o "$DOTFILES/.zshrc" "$HOME/.zshrc"

# Link git config
symlinkit -o "$DOTFILES/.gitconfig" "$HOME/.gitconfig"

# Merge config directory
symlinkit -m "$DOTFILES/.config" "$HOME/.config"

# Link scripts
symlinkit -m "$DOTFILES/scripts" "$HOME/bin"

System Administration

Audit Symlinks

# List all symlinks in home directory
symlinkit --list ~/

# List symlinks in system directory
sudo symlinkit --list /usr/local/bin

# Pipe to file for documentation
symlinkit --list ~/ > symlink-audit.txt

Find Broken Symlinks

# Check home directory
symlinkit --broken ~/

# Check system-wide
sudo symlinkit --broken /

# Check specific directory
symlinkit --broken /usr/local/bin

Maintenance Script

#!/bin/bash
# symlink-maintenance.sh

echo "=== Symlink Maintenance ==="

# Find broken links
echo "Checking for broken symlinks..."
symlinkit --broken ~/

# If broken links found, fix them
read -p "Fix broken symlinks? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    symlinkit --fix-broken ~/
fi

echo "Maintenance complete."

Development Workflows

Link Project Scripts

# Link scripts to local bin
symlinkit -m ~/projects/my-app/bin ~/bin

# Preview first
symlinkit --dry-run -m ~/projects/my-app/bin ~/bin

Shared Configurations

# Link shared configs across projects
symlinkit -o ~/shared-configs/eslintrc.js ~/project1/.eslintrc.js
symlinkit -o ~/shared-configs/eslintrc.js ~/project2/.eslintrc.js
symlinkit -o ~/shared-configs/eslintrc.js ~/project3/.eslintrc.js

Development Environment Setup

#!/bin/bash
# dev-env-setup.sh

PROJECT="$HOME/projects/my-app"

# Link config files
symlinkit -o "$PROJECT/configs/.eslintrc.js" "$PROJECT/.eslintrc.js"
symlinkit -o "$PROJECT/configs/.prettierrc" "$PROJECT/.prettierrc"

# Link scripts
symlinkit -m "$PROJECT/scripts" "$HOME/bin"

echo "Development environment ready!"

Inspection & Repair

Regular Maintenance

# Step 1: List all symlinks
symlinkit --list ~/

# Step 2: Check for broken links
symlinkit --broken ~/

# Step 3: Fix broken links if found
symlinkit --fix-broken ~/

Interactive Repair Session

$ symlinkit --fix-broken ~/

/home/user/.config/deleted -> /old-path (broken)
[d]elete / [a]ll delete / [u]pdate / [s]kip > d
❌ Deleted: /home/user/.config/deleted

/home/user/bin/old-script -> /tmp/removed.sh (broken)
[d]elete / [a]ll delete / [u]pdate / [s]kip > u
Enter new target path:
/home/user/scripts/deploy.sh
✅ Updated: /home/user/bin/old-script -> /home/user/scripts/deploy.sh

Summary: 1 deleted, 1 updated, 0 skipped

Safe Workflows

Always Preview First

# BAD: Direct overwrite
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc  # RISKY!

# GOOD: Preview then apply
symlinkit --dry-run -o ~/dotfiles/.vimrc ~/.vimrc
# Review output...
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc

Test Before Production

# Test in temp directory first
mkdir /tmp/test-symlinks
symlinkit -m ~/dotfiles/test /tmp/test-symlinks

# Verify it works
ls -la /tmp/test-symlinks

# Apply to real location
symlinkit -m ~/dotfiles/configs ~/.config

# Clean up test
rm -rf /tmp/test-symlinks

Migration Scenarios

Migrating to Symlinked Dotfiles

Before:

~/.bashrc (regular file)
~/.vimrc (regular file)
~/.config/nvim/ (regular directory)

Steps:

# 1. Backup current configs
cp ~/.bashrc ~/backup/.bashrc
cp ~/.vimrc ~/backup/.vimrc
cp -r ~/.config/nvim ~/backup/nvim

# 2. Move configs to dotfiles repo
mv ~/.bashrc ~/dotfiles/.bashrc
mv ~/.vimrc ~/dotfiles/.vimrc
mv ~/.config/nvim ~/dotfiles/nvim

# 3. Create symlinks
symlinkit -o ~/dotfiles/.bashrc ~/.bashrc
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc
symlinkit -o ~/dotfiles/nvim ~/.config/nvim

# 4. Verify
symlinkit --list ~/

After:

~/.bashrc -> ~/dotfiles/.bashrc
~/.vimrc -> ~/dotfiles/.vimrc
~/.config/nvim -> ~/dotfiles/nvim

Automation Examples

Dotfiles Install Script

#!/bin/bash
# install-dotfiles.sh

set -e

DOTFILES="$HOME/dotfiles"

echo "Installing dotfiles..."

# Clone dotfiles repo
if [[ ! -d "$DOTFILES" ]]; then
    git clone https://github.com/username/dotfiles.git "$DOTFILES"
fi

# Link configs
symlinkit -o "$DOTFILES/.bashrc" "$HOME/.bashrc"
symlinkit -o "$DOTFILES/.zshrc" "$HOME/.zshrc"
symlinkit -o "$DOTFILES/.gitconfig" "$HOME/.gitconfig"

# Merge config directory
symlinkit -m "$DOTFILES/.config" "$HOME/.config"

echo "✅ Dotfiles installed successfully!"

Cleanup Script

#!/bin/bash
# cleanup-symlinks.sh

DIR="${1:-$HOME}"

echo "Checking for broken symlinks in $DIR..."
symlinkit --broken "$DIR"

read -p "Remove all broken symlinks? [y/N] " -n 1 -r
echo

if [[ $REPLY =~ ^[Yy]$ ]]; then
    # Use --fix-broken with 'a' for delete all
    echo "a" | symlinkit --fix-broken "$DIR"
    echo "✅ Cleanup complete!"
else
    echo "Cancelled."
fi

Platform-Specific Examples

macOS

# Ensure coreutils is installed
brew install coreutils

# Link Application Support configs
symlinkit -m ~/dotfiles/Library/Application\ Support ~/Library/Application\ Support

# Link LaunchAgents
symlinkit -o ~/dotfiles/LaunchAgents/com.example.plist ~/Library/LaunchAgents/

Linux

# Link systemd user services
symlinkit -m ~/dotfiles/systemd ~/.config/systemd/user

# Link desktop entries
symlinkit -m ~/dotfiles/applications ~/.local/share/applications

WSL

# Link Windows configs (if needed)
symlinkit -o ~/dotfiles/.wslconfig /mnt/c/Users/username/.wslconfig

# Link standard Linux configs
symlinkit -m ~/dotfiles/.config ~/.config

Common Patterns

Config File

symlinkit -o ~/dotfiles/.bashrc ~/.bashrc

Config Directory

symlinkit -m ~/dotfiles/.config ~/.config

Single Directory

symlinkit -o ~/dotfiles/nvim ~/.config/nvim

Scripts Directory

symlinkit -m ~/dotfiles/scripts ~/bin

Cleanup

symlinkit -dr ~/old-links

Troubleshooting Workflows

"File exists" Error

# Error: destination already exists
# Solution: Use overwrite mode
symlinkit -o ~/source ~/dest

# Or: Delete existing first, then create
rm -rf ~/dest
symlinkit -c ~/source ~/dest

Permission Denied

# Error: Permission denied
# Solution: Use sudo (with caution!)
sudo symlinkit -o ~/source /etc/config

Broken Symlinks After Moving Files

# Find what broke
symlinkit --broken ~/

# Fix interactively
symlinkit --fix-broken ~/

Next Steps

Symlinkit Wiki Navigation

Getting Started

Features & Functionality

Development & Contributing

Clone this wiki locally