Add support for environment variables and '~' in paths

- Add utility to expand environment variables
- Revise rc-file searching to use new mechanism
- Expand environment variables when opening files
- Adapt filesystem unit tests for new mechanism
Fix restoring original environment during unit testing
Fix restoring HOME, etc.
Merge branch 'fixes-filenames'