Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: backing up with zsh



On Apr 18,  9:36am, TGAPE! wrote:
} Subject: Re: backing up with zsh
}
} ~/.P;for x in **/*(D)
} do
} 	if [ $x != ${x#pics} && $(file $x | grep -c picture) -gt 0 ]; then
} 		n=pics/${x##*/}
} 		ln $x $n
} 		for y in **/*(D.)
} 		do
} 			sed "s@$x@$n@g" $y > /tmp/nopics.$$
} 			mv /tmp/nopics.$$ $y
} 		done
} 		rm $x
} 	fi
} done
} 
} should go a long way to moving all your pictures and fixing your links.

Various remarks:

Using ~/.P; like that only works if autocd is set.

What's the reason for including directories in the glob for the outer loop?

It's probably a -lot- faster to run "file" on multiple filenames, rather
than on every name individually.

Most implementations of /etc/magic (the "file" database) use "image" rather
than "picture" for GIF, JPEG, etc. files.

${x:t} is equivalent to ${x##*/}.

The second parameter to "ln" can be the name of a directory, so it can be
run once on all the picture files.

The inner loop runs sed on both the html files and the picture files, which
is probably going to corrupt the pictures.

You're running sed and then mv once per picture file per every other file.
Once per html document should be enough.

/tmp is probably in another filesystem, which means the mv is no better
than a cp.  Why put the temp file there?

So that leaves us with:

    function shufflepics() {
	setopt localoptions extendedglob
	local pics docs sedit
	cd ~/.P
	file **/*~pics/*(D.) | while read name type
	do
	    name=${name%:*}
	    case ${(L)type} in
	    (*image*|*picture*)
		sedit=($sedit -e "s@${name}@pics/${name:t}@g")
		pics=($pics $name);;
	    (*html*)
		docs=($docs $name);;
	    esac
	done
	ln $pics pics
	for f in $docs
	do
	    sed $sedit $f > $$-${f:t} && mv $$-${f:t} $f
	done
	rm -f $pics $$-*
    }

How's that?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author