From 97d0f2f1d05bf51f65ca27c8f6f995c9db2c49f0 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Thu, 12 Nov 2015 10:33:25 -0800 Subject: [PATCH] Prune broken symlinks now confirms. --- dotfiles/zshrc.d/prune-broken-symlinks.zsh | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dotfiles/zshrc.d/prune-broken-symlinks.zsh b/dotfiles/zshrc.d/prune-broken-symlinks.zsh index 458d2e4..7127807 100644 --- a/dotfiles/zshrc.d/prune-broken-symlinks.zsh +++ b/dotfiles/zshrc.d/prune-broken-symlinks.zsh @@ -1,4 +1,26 @@ prune-broken-symlinks() { setopt localoptions nounset - find $1 -type l -xtype l -print -delete + local ASK + local DIR + local FINDCMD + local i + + if [[ "${1:-}" == "-y" ]] ; then + ASK=0 + shift + else + ASK=1 + fi + DIR=${1:-.} + FINDCMD=(find ${DIR} -type l -xtype l) + if (($ASK)) ; then + ${FINDCMD} -print + echo -n 'Delete these links? [y/n] ' + if read -q ; then + ${FINDCMD} -delete + fi + echo + else + ${FINDCMD} -print -delete + fi }