getUserDirectoryNames function

Set<String> getUserDirectoryNames()

Gets the set of user directory names that xdg knows about.

These are not paths, they are names of xdg values. Call getUserDirectory to get the associated directory.

These are the names of the variables in "configHome/user-dirs.dirs", with the XDG_ prefix removed and the _DIR suffix removed.

Implementation

Set<String> getUserDirectoryNames() {
  final File configFile = File(path.join(configHome.path, 'user-dirs.dirs'));
  List<String> contents;
  try {
    contents = configFile.readAsLinesSync();
  } on FileSystemException {
    return const <String>{};
  }
  final Set<String> result = <String>{};
  final RegExp dirRegExp =
      RegExp(r'^\s*XDG_(?<dirname>[^=]*)_DIR\s*=\s*(?<dir>.*)\s*$');
  for (final String line in contents) {
    final RegExpMatch? match = dirRegExp.firstMatch(line);
    if (match == null) {
      continue;
    }
    result.add(match.namedGroup('dirname')!);
  }
  return result;
}