expandPath function

String expandPath(
  1. String path
)

Expand ~ and resolve relative paths to absolute.

Implementation

String expandPath(String path) {
  if (path.startsWith('~/') || path == '~') {
    final home =
        Platform.environment['HOME'] ??
        Platform.environment['USERPROFILE'] ??
        '';
    return p.join(home, path.substring(path.startsWith('~/') ? 2 : 1));
  }
  if (!p.isAbsolute(path)) {
    return p.join(Directory.current.path, path);
  }
  return path;
}