smartFolderGenerator top-level property

FigGenerator smartFolderGenerator
final

Implementation

final FigGenerator smartFolderGenerator = FigGenerator(
  trigger: '/',
  script: (List<String> tokens, FigGeneratorContext? ctx) {
    final home = ctx?.getEnv('HOME') ?? '';
    return ['ls', '-1A', '$home/Library/Saved Searches/'];
  },
  postProcess: (String out, [List<String>? tokens]) {
    return out
        .split('\n')
        .where((file) => file.endsWith('savedSearch'))
        .map((path) {
      var components = path.split('/');
      var filename = components.last;
      return FigSuggestion(
        name: filename.substring(0, filename.indexOf('.')),
        displayName: filename,
        icon: 'fig://$path',
        description: 'Smart folder',
      );
    }).toList();
  },
);