#!/bin/bash # # _scripts/path-cleanup # # Developed by Lubomir Host 'rajo' # Copyright (c) 2005 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-06-11 - created # # $Platon: Platon.SK/office/_scripts/path-cleanup,v 1.1 2005-06-11 01:46:58 rajo Exp $ # # Make cleanup in path: # # 1. - remove duplicated '/././' # 2. - remove duplicated '//' # 2. - remove directories 'a/b/../c/' --> 'a/c/' # comment out next line for debugging DEBUG=":" # uncomment next line and progress bar is turned off #PROGRESSBAR=":" OUT="/dev/stderr" REGEXP='s%/\(\./\)\+%/%g; s%/\+%/%g; s%\([^/]\+\)/\.\./%%g; s%/\.\?$%%g;' make_clanup() { # {{{ file="$1" $DEBUG echo "--> Starting with '$file'" > $OUT $PROGRESSBAR echo -n "Cleaning path ." > $OUT old="$file" file=`echo "$file" | sed -e "$REGEXP"` $DEBUG echo " first iter: '$file'" > $OUT while [ "x$old" != "x$file" ]; do old="$file" file=`echo "$file" | sed -e "$REGEXP"` $DEBUG echo " iter: '$file'" > $OUT $PROGRESSBAR echo -n "." > $OUT done $PROGRESSBAR echo " done." > $OUT echo "$file" } # }}} for filename in $*; do make_clanup "$filename" done