diff --git a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift index 95a90232d..9387f4a05 100644 --- a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift @@ -43,8 +43,16 @@ public struct CompletionShell: RawRepresentable, Hashable, CaseIterable { /// Returns an instance representing the current shell, if recognized. public static func autodetected() -> CompletionShell? { // FIXME: This retrieves the user's preferred shell, not necessarily the one currently in use. +#if os(Windows) + var buffer: UnsafeMutablePointer? + var length: Int = 0 + guard _dupenv_s(&buffer, &length, "SHELL") != 0, let shellVar = buffer else { return nil } + let shellParts = String(cString: shellVar).split(separator: "/") + free(buffer) +#else guard let shellVar = getenv("SHELL") else { return nil } let shellParts = String(cString: shellVar).split(separator: "/") +#endif return CompletionShell(rawValue: String(shellParts.last ?? "")) }