The safe-rm.sh
script is a safety tool for Unix-like systems using the Zsh shell. It overrides the standard rm
(remove) command to provide additional safeguards when deleting directories, especially those that are part of a Git repository. This script helps prevent accidental deletion of repositories.
- Git Repository Detection: Automatically detects if a directory is a Git repository.
- Repository Details Display: Shows the current branch and last commit message for Git repositories.
- Deletion Confirmation: Prompts for user confirmation before deleting Git repositories.
- Color-Coded Warnings: Uses colored text for better visibility of warnings and messages.
- Download the
safe-rm.sh
script. - Add the following line to your
~/.zshrc
file to source the script:
source /path/to/safe-rm.sh
- Restart your terminal session or source your
~/.zshrc
file:
source ~/.zshrc
Once installed, use the rm
command as you normally would. The script will automatically invoke the safe_rm
function when you attempt to remove any directory.
Example:
rm my_directory
If my_directory
is a Git repository, you will see a detailed warning and be prompted for confirmation before deletion.
- This script was tested only in Zsh shell but since Zsh is built on top of bash this probably works on bash too.
- It only affects directories recognized as Git repositories.
- The aliasing is effective only in the shell sessions where it's sourced.