expandHome function

String expandHome(
  1. String path
)

Expands a leading ~ to the current user's home directory.

Implementation

String expandHome(String path) {
  if (!path.startsWith('~')) return path;
  final home =
      Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'] ?? '';
  if (path == '~') return home;
  if (path.startsWith('~/') || path.startsWith('~\\')) {
    return '$home${path.substring(1)}';
  }
  return path;
}