knownHosts top-level property

FigGenerator knownHosts
final

Implementation

final FigGenerator knownHosts = FigGenerator(
  script: ['sh', '-c', 'cat ~/.ssh/known_hosts'],
  postProcess: (String out, [List<String>? tokens]) {
    final suggestions = out
        .split('\n')
        .map((line) {
          final match = knownHostRegex.firstMatch(line);
          return match?.group(0);
        })
        .where((value) => value != null)
        .toSet()
        .map((knownHost) {
          final hostName = knownHost!;
          final userPart =
              (tokens != null && tokens.length > 1 && tokens[1].endsWith('@'))
                  ? tokens[1]
                  : '';
          final name = userPart.isNotEmpty ? '$userPart$hostName' : hostName;
          return FigSuggestion(
            name: name,
            description: 'SSH host',
          );
        })
        .toList();

    return suggestions;
  },
  trigger: '@',
);