macOS: command-palette-entry is now visible in macOS

This commit is contained in:
Mitchell Hashimoto
2025-12-24 14:28:12 -08:00
parent 017021787c
commit 12523ca61c
2 changed files with 24 additions and 1 deletions

View File

@@ -64,7 +64,7 @@ struct TerminalCommandPaletteView: View {
// Sort the rest. We replace ":" with a character that sorts before space
// so that "Foo:" sorts before "Foo Bar:". Use sortKey as a tie-breaker
// for stable ordering when titles are equal.
options.append(contentsOf: (jumpOptions + terminalOptions).sorted { a, b in
options.append(contentsOf: (jumpOptions + terminalOptions + customEntries).sorted { a, b in
let aNormalized = a.title.replacingOccurrences(of: ":", with: "\t")
let bNormalized = b.title.replacingOccurrences(of: ":", with: "\t")
let comparison = aNormalized.localizedCaseInsensitiveCompare(bNormalized)
@@ -135,6 +135,19 @@ struct TerminalCommandPaletteView: View {
}
}
/// Custom commands from the command-palette-entry configuration.
private var customEntries: [CommandOption] {
guard let appDelegate = NSApp.delegate as? AppDelegate else { return [] }
return appDelegate.ghostty.config.commandPaletteEntries.map { c in
CommandOption(
title: c.title,
description: c.description
) {
onAction(c.action)
}
}
}
/// Commands for jumping to other terminal surfaces.
private var jumpOptions: [CommandOption] {
TerminalController.all.flatMap { controller -> [CommandOption] in

View File

@@ -622,6 +622,16 @@ extension Ghostty {
let str = String(cString: ptr)
return Scrollbar(rawValue: str) ?? defaultValue
}
var commandPaletteEntries: [Ghostty.Command] {
guard let config = self.config else { return [] }
var v: ghostty_config_command_list_s = .init()
let key = "command-palette-entry"
guard ghostty_config_get(config, &v, key, UInt(key.lengthOfBytes(using: .utf8))) else { return [] }
guard v.len > 0 else { return [] }
let buffer = UnsafeBufferPointer(start: v.commands, count: v.len)
return buffer.map { Ghostty.Command(cValue: $0) }
}
}
}