Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<CChar>?
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would swap the two things, doing a defer { free(buffer) } and then just returning the processed value. However, the separator is unlikely to be / and more likely to be \ if there was such a variable, though it could be either.

#else
guard let shellVar = getenv("SHELL") else { return nil }
let shellParts = String(cString: shellVar).split(separator: "/")
#endif
return CompletionShell(rawValue: String(shellParts.last ?? ""))
}

Expand Down