mirror of
https://github.com/Matir/skel.git
synced 2026-05-26 05:29:09 -07:00
32 lines
560 B
Bash
32 lines
560 B
Bash
prune-broken-symlinks() {
|
|
setopt localoptions nounset
|
|
local ASK
|
|
local DIR
|
|
local FINDCMD
|
|
local i
|
|
|
|
if [[ "${1:-}" == "-y" ]] ; then
|
|
ASK=0
|
|
shift
|
|
else
|
|
ASK=1
|
|
fi
|
|
DIR=${1:-.}
|
|
FINDCMD=(find -L ${DIR} -xdev -type l)
|
|
if (($ASK)) ; then
|
|
local FILES
|
|
FILES=`${FINDCMD} -print`
|
|
if [[ "${FILES}" == "" ]] ; then
|
|
return 0
|
|
fi
|
|
echo ${FILES}
|
|
echo -n 'Delete these links? [y/n] '
|
|
if read -q ; then
|
|
${FINDCMD} -print0 | xargs -r -0 rm
|
|
fi
|
|
echo
|
|
else
|
|
${FINDCMD} -print0 | xargs -r -0 rm
|
|
fi
|
|
}
|