From 7b896407775b2a907d6559e97ed1ff2e062b0619 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Mon, 2 Nov 2015 22:02:04 +0100 Subject: [PATCH] Add the clean command. Sometimes it is useful to remove temporary files from a directory. I used to do this with a shell script located in /usr/bin/, however that wasn't very convenient. Putting the script in the .zshrc allows to maintains the very small script with all the dotfiles instead of copying the script from machines to machines. --- .zshrc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.zshrc b/.zshrc index 3b533ce..8b536fe 100644 --- a/.zshrc +++ b/.zshrc @@ -81,3 +81,28 @@ if hash dig 2>/dev/null; then fi } fi + +clean() +{ + clean_dir() + { + local dir="$1" + if [ -d "$dir" ]; then + find "$dir" -name "*~" -print -delete + find "$dir" -name ".*~" -print -delete + find "$dir" -name "#*#" -print -delete + else + echo "$dir: not a directory" + fi + } + + if [ $# -ne 0 ]; then + for dir in "$@"; do + clean_dir "$dir" + done + else + clean_dir "./" + fi + + unfunction clean_dir +}