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
#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.."