Fix $HOME -> ~ replacement
When computing SWD, $HOME should only be replaced with ~ if it's at the beginning of the string and only once.
This fixes the following:
/home/user/home/user -> ~/home/user (previously ~~)
/foo/home/user -> /foo/home/user (previously /foo~)
Edited by Kamil Koczurek