killobsolete() { # files directly in ~ formerly used, now obsolete # subdirs of ~ checked automatically local suspected=".emacs" # init tempfiles we need to run diff on local found="/tmp/.myshell_found" local pulled="/tmp/.myshell_pulled" # detect files found locally for i in $(gunzip -c cfg.tar.gz | tar -tf -); do echo $(dirname "$i"); done | grep -v '^.$' | sort | uniq | xargs find | sort | uniq | \ grep -v ".myshell/.*_local*" > "$found" # detect suspected files for f in $(find $suspected 2>/dev/null); do echo "$f" >> "$found"; done # sort found list cat "$found" | sort | uniq > "$found.x" ; mv "$found.x" "$found" # list files pulled from upstream for i in $(gunzip -c cfg.tar.gz | tar -tf -); do echo "$i"; echo $(dirname "$i"); done | grep -v '^.$' | sed "s|\/$||g" | sort | uniq > "$pulled" # list obsolete files local num=$(diff "$pulled" "$found" | grep '>' | cut -b3- | wc -l) if [ $num -gt 0 ]; then echo -e "${cyellow} ++ files found to be obsolete${creset}"; diff "$pulled" "$found" | grep '>' | cut -b3-; # prompt for deletion echo -e "${cyellow} ++ kill obsolete? [yN]${creset}" read ans if [[ "$ans" == "y" ]]; then for i in $(diff "$pulled" "$found" | grep '>' | cut -b3-); do if [ -d "$i" ]; then rm -rf "$i" else rm -f "$i" fi done fi fi # dispose of tempfiles rm -f "$pulled" "$found" }