Skip to content

Instantly share code, notes, and snippets.

@aziis98
Last active January 19, 2022 04:47
Show Gist options
  • Save aziis98/5db2a8efb07c1fa666e740f8c0b72b6a to your computer and use it in GitHub Desktop.
Save aziis98/5db2a8efb07c1fa666e740f8c0b72b6a to your computer and use it in GitHub Desktop.
Script to automatically symlink all scripts to the correct directories with the TARGET_PATH directive.
#!/bin/bash
# Cleans unlinked dotfiles in all used folders
#
# Author: aziis98
# Date: 06/01/2021
set -euo pipefail
TRACKED_DOTFILES_FILE=~/.cache/dotfiles/tracked
if [[ ! -e "$TRACKED_DOTFILES_FILE" ]]; then
echo -e "Run \"dotfiles_link\" at least once to start tracking symlinks!"
exit 1
fi
DELETE_COUNT=0
while read tracked_file; do
if [[ ! -e "$tracked_file" ]]; then
DELETE_COUNT=$(($DELETE_COUNT + 1))
sed -i "\|$tracked_file|d" $TRACKED_DOTFILES_FILE
rm -v "$tracked_file"
fi
done < "$TRACKED_DOTFILES_FILE"
echo "Deleted $DELETE_COUNT broken link"$([[ "$DELETE_COUNT" -ne 1 ]] && echo -e "s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment