-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-symlinks
More file actions
executable file
·34 lines (29 loc) · 876 Bytes
/
clean-symlinks
File metadata and controls
executable file
·34 lines (29 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# list and offer to remove all broken symlinks recursing from your current dir
dir_excludes="\( -path ${HOME}/.mozilla -o -path ${HOME}/.local/share/Steam\)"
remove_symlinks() {
# remove all broken symlinks
find "${HOME}" -xtype l -exec rm -v {} \;
}
log_symlinks() {
# log broken symlinks to a tmpfile
output="$(mktemp --suffix '.txt')"
find "${HOME}" -xtype l ! -exec test -e {} \; -print >"${output}" &&
printf -- '%s\n' "Symlinks output to ${output} for review."
printf -- '%s\n' "Exiting program without removing any symlinks."
exit 1
}
# find broken symlinks (won't work on OSX)
printf -- 'Broken symlinks in "%s":\n' "${HOME}"
find "${HOME}" -xtype l ! -exec test -e {} \; -print
printf -- '%s' "Remove broken symlinks? [Y/n] "
read -r remove
case "$remove" in
y | Y)
remove_symlinks
;;
*)
log_symlinks
;;
esac
exit 0