loggedInUsersHome property

String get loggedInUsersHome

Attempts to retrive the logged in user's home directory.

This is intended when a script is run as sudo and we need to get the home directory of the original user.

Implementation

String get loggedInUsersHome {
  final user = loggedInUser;

  final String pathToHome;

  if (Platform.isMacOS) {
    pathToHome = MacOSUtils.loggedInUsersHome(user);
  } else {
    final parts = 'getent passwd $user'.firstLine!.split(':');

    pathToHome = parts[5];
  }
  return pathToHome;
}