compressTilde function
compress tilde with path
assume the current user is 'kaguya'
- Windows
- C:\Users\kaguya\Downloads\ft\README.md -> %USERPROFILE%\Downloads\ft\README.md
- MacOS:
- /Users/kaguya/Downloads/ft/README.md -> ~/Downloads/ft/README.md
- Linux:
- /home/kaguya/Downloads/ft/README.md -> ~/Downloads/ft/README.md
Implementation
String compressTilde(String path) {
if (homePath.isNotEmpty && p.isAbsolute(path) && path.startsWith(homePath)) {
if (path == homePath) return homePattern;
final reslovePath =
p.join(homePattern, path.substring(homePath.length + 1));
return reslovePath;
}
return path;
}