pkgutilGenerators top-level property

Map<String, FigGenerator> pkgutilGenerators
final

Implementation

final Map<String, FigGenerator> pkgutilGenerators = {
  // BOM files
  'bom': FigGenerator(
    script: ['find', '.', '-type', 'f', '-name', '*.bom', '-maxdepth', '1'],
    postProcess: (String out, [List<String>? tokens]) {
      return out
          .split('\n')
          .map((filepath) => FigSuggestion(
                name: filepath.replaceFirst('./', ''),
              ))
          .toList();
    },
  ),
  // Installed package ids
  'packageIds': FigGenerator(
    script: ['pkgutil', '--pkgs'],
    splitOn: '\n',
  ),
  // .pkg files
  'pkgs': FigGenerator(
    script: ['find', '.', '-type', 'f', '-name', '*.pkg', '-maxdepth', '1'],
    postProcess: (String out, [List<String>? tokens]) {
      return out
          .split('\n')
          .map((filepath) => FigSuggestion(
                name: filepath.replaceFirst('./', ''),
              ))
          .toList();
    },
  ),
  // group ids
  'groupIds': const FigGenerator(
    script: ['pkgutil', '--groups'],
    splitOn: '\n',
  ),
  // filenames within a package
  'pkgFilenames': FigGenerator(
    trigger: '/',
    script: (List<String> tokens) {
      final editPkgIndex = tokens.indexOf('--edit-pkg');
      final pkgIdIndex = editPkgIndex + 1;
      if (editPkgIndex == -1 || pkgIdIndex >= tokens.length) {
        return [];
      }

      final pkgId = tokens[pkgIdIndex];
      return ['pkgutil', '--files', pkgId];
    },
    postProcess: (String out, [List<String>? tokens]) {
      if (tokens == null) return [];
      final pathPrefix = tokens.isNotEmpty ? tokens.last : '';
      return _postProcessPkgFilenames(out, pathPrefix);
    },
  ),
};