moved the main functionality to a function to make it testable
added some tests
added test with spaces in path
more natural quoting
no need for index
removed the index tests
simplified the regexes in the sed
removed unnecessary quotes
renamed OLDPWD to oldpwd to avoid messing with the *real* OLDPWD
replaced sed with perl for the -si case