From: Bernhard Tittelbach Date: Fri, 8 Jul 2011 10:34:42 +0000 (+0200) Subject: zshrc: improve purge() function. X-Git-Tag: v0.4.00~14 X-Git-Url: https://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=5dd23e2f094bfa37e5555583607f9698752487f7 zshrc: improve purge() function. While at it only delete FILES, not e.g. *~ directories. --- diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index 13bccb2..271cedb 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -790,9 +790,16 @@ Runs a command in $SHELL with profiling enabled (See startup variable ZSH_PROFILE_RC above). : **purge()** -Removes typical temporary files (i. e. files like "*~", ".*~", "#*#", "*.o", -"a.out", "*.core", "*.cmo", "*.cmi" and ".*.swp") from current directory. -Asks for confirmation. +Removes temporary files from current directory. Asks for confirmation. Uses sudo if necessary. +In detail it purges + - common temp files like "*~", ".*~", "#*#", "*.o", "a.out", "*.orig", "*.rej", "*.cmo", "*.cmi" and ".*.swp" + - core dumps + - debconf backup files: "*.dpkg-old", "*.dkpg-new", "*.dpkg-dist" + - gentoo dispatch-conf backups: ".cfg0000_*", ".mrg0000_*" + - precompiled python code ("*.pyc", "*.pyo") as long as matching "*.py" source is also present + - LaTeX temp files i.e. "*.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)" for any present "*.tex" + - ghc temp files, as long as matching "*.hs" or "*.lhs" is also present + - "*.mood(D)" Files which are missing their corresponding audio file : **readme()** Opens all README-like files in current working directory with the program diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 041bae3..399ac4f 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -3611,15 +3611,24 @@ lcheck() { #f5# Clean up directory - remove well known tempfiles purge() { - FILES=(*~(N) .*~(N) \#*\#(N) *.o(N) a.out(N) *.core(N) *.cmo(N) *.cmi(N) .*.swp(N)) - NBFILES=${#FILES} + emulate -L zsh + setopt HIST_SUBST_PATTERN + local -a TEXTEMPFILES GHCTEMPFILES PYTEMPFILES FILES + TEXTEMPFILES=(*.tex(N:s/%tex/'(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(N)'/)) + GHCTEMPFILES=(*.(hs|lhs)(N:r:s/%/'.(hi|hc|(p|u|s)_(o|hi))(N)'/)) + PYTEMPFILES=(*.py(N:s/%py/'(pyc|pyo)(N)'/)) + LONELY_MOOD_FILES=((*.mood)(NDe:'local -a AF;AF=( ${${REPLY#.}%mood}(mp3|flac|ogg|asf|wmv|aac)(N) ); [[ -z "$AF" ]]':)) + FILES=(*~(.N) \#*\#(.N) *.o(.N) a.out(.N) (*.|)core(.N) *.cmo(.N) *.cmi(.N) .*.swp(.N) *.(orig|rej)(.DN) *.dpkg-(old|dist|new)(DN) ._(cfg|mrg)[0-9][0-9][0-9][0-9]_*(N) ${~TEXTEMPFILES} ${~GHCTEMPFILES} ${~PYTEMPFILES} ${LONELY_MOOD_FILES}) + local NBFILES=${#FILES} + local CURDIRSUDO="" + [[ ! -w ./ ]] && CURDIRSUDO=$SUDO if [[ $NBFILES > 0 ]] ; then - print $FILES + print -l $FILES local ans echo -n "Remove these files? [y/n] " read -q ans if [[ $ans == "y" ]] ; then - rm ${FILES} + $CURDIRSUDO rm ${FILES} echo ">> $PWD purged, $NBFILES files removed" else echo "Ok. .. then not.."