-
-
Save wieczorek1990/f29b3aeb7c132c51a8fd to your computer and use it in GitHub Desktop.
Safe symbolic links removal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Useful when using `set mark-symlinked-directories on` in inputrc | |
# Install trash-cli first or replace `trash` with `rm -rf` | |
r() { | |
for arg | |
do | |
s=${#arg} | |
arg2=${arg:0:s-1} | |
if [ -L "$arg2" ] | |
then | |
if [[ "${arg: -1}" == '/' && -d "$arg" ]] | |
then | |
echo "Preserving symlinked directory '$arg'" | |
fi | |
else | |
trash "${arg}" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment