Skip to content

Add Makefile target to detect and clean up broken dotfile symlinks #43

@xtetsuji

Description

@xtetsuji

Problem

When dotfiles are renamed or removed from the repository, broken symlinks can remain in the home directory. These broken symlinks point to non-existent files and can cause confusion or errors.

For example:

  • If we rename vimrc to vim_config, the old ~/.vimrc symlink becomes broken
  • If we remove a dotfile from the repository, its corresponding ~/.dotfile symlink becomes invalid
  • Currently, there's no automated way to detect and clean up these broken symlinks

Proposed Solution

Add a new Makefile target clean-broken-symlinks that:

  1. Detects broken dotfile symlinks in the home directory (~/.??*)
  2. Filters for repository-related symlinks (pointing to this dotfiles repository)
  3. Interactively prompts for each broken symlink deletion
  4. Shows clear information about what will be removed

Suggested implementation:

clean-broken-symlinks:
	@echo "Checking for broken dotfile symlinks in home directory..."
	@for link in ~/.??* ; do \
		if [ -L "$$link" ] && ! [ -e "$$link" ] ; then \
			target=$$(readlink "$$link") ; \
			if [[ "$$target" == "$(CURDIR)"/* ]] ; then \
				echo "Found broken symlink: $$link -> $$target" ; \
				read -p "Remove $$link? [y/N]: " confirm ; \
				if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ] ; then \
					rm -v "$$link" ; \
				fi ; \
			fi ; \
		fi ; \
	done

Features:

  • Safe: Only targets symlinks pointing to this dotfiles repository
  • Interactive: Asks for confirmation before each deletion
  • Informative: Shows what symlink points where
  • Non-destructive: Skips regular files and valid symlinks

Usage:

make clean-broken-symlinks

This would help maintain a clean home directory and prevent issues caused by stale symlinks.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions