completionConfigDir property

  1. @visibleForTesting
Directory get completionConfigDir

Define the Directory in which the completion configuration files will be stored.

If isWindows is true, it will return the directory defined by %LOCALAPPDATA%/DartCLICompletion

If isWindows is false, it will return the directory defined by $XDG_CONFIG_HOME/.dart_cli_completion or $HOME/.dart_cli_completion

Implementation

@visibleForTesting
Directory get completionConfigDir {
  if (isWindows) {
    // Use localappdata on windows
    final localAppData = environment['LOCALAPPDATA']!;
    return Directory(path.join(localAppData, 'DartCLICompletion'));
  } else {
    // Try using XDG config folder
    var dirPath = environment['XDG_CONFIG_HOME'];
    // Fallback to $HOME if not following XDG specification
    if (dirPath == null || dirPath.isEmpty) {
      dirPath = environment['HOME'];
    }
    return Directory(path.join(dirPath!, '.dart-cli-completion'));
  }
}