native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #103 from supabitapp/hotkeys-worktree-and-tabs-numeric-shortcuts

Remap numeric hotkeys for worktree and tab switching

authored by

khoi and committed by
GitHub
b7790a6e 7ab1d6ba

+97 -2
+35
supacode/App/AppShortcuts.swift
··· 26 26 return parts.joined(separator: "+") 27 27 } 28 28 29 + var ghosttyUnbindArgument: String { 30 + "--keybind=\(ghosttyKeybind)=unbind" 31 + } 32 + 29 33 var display: String { 30 34 let parts = displayModifierParts + [keyEquivalent.display] 31 35 return parts.joined() ··· 55 59 } 56 60 57 61 enum AppShortcuts { 62 + private struct TabSelectionBinding { 63 + let unicode: String 64 + let physical: String 65 + let tabIndex: Int 66 + } 67 + 68 + private static let tabSelectionBindings: [TabSelectionBinding] = [ 69 + TabSelectionBinding(unicode: "1", physical: "digit_1", tabIndex: 1), 70 + TabSelectionBinding(unicode: "2", physical: "digit_2", tabIndex: 2), 71 + TabSelectionBinding(unicode: "3", physical: "digit_3", tabIndex: 3), 72 + TabSelectionBinding(unicode: "4", physical: "digit_4", tabIndex: 4), 73 + TabSelectionBinding(unicode: "5", physical: "digit_5", tabIndex: 5), 74 + TabSelectionBinding(unicode: "6", physical: "digit_6", tabIndex: 6), 75 + TabSelectionBinding(unicode: "7", physical: "digit_7", tabIndex: 7), 76 + TabSelectionBinding(unicode: "8", physical: "digit_8", tabIndex: 8), 77 + TabSelectionBinding(unicode: "9", physical: "digit_9", tabIndex: 9), 78 + TabSelectionBinding(unicode: "0", physical: "digit_0", tabIndex: 10), 79 + ] 80 + 58 81 static let newWorktree = AppShortcut(key: "n", modifiers: .command) 59 82 static let openSettings = AppShortcut(key: ",", modifiers: .command) 60 83 static let openFinder = AppShortcut(key: "o", modifiers: .command) ··· 95 118 selectWorktree9, 96 119 selectWorktree0, 97 120 ] 121 + 122 + static let tabSelectionGhosttyKeybindArguments: [String] = tabSelectionBindings.flatMap { binding in 123 + [ 124 + "--keybind=ctrl+\(binding.unicode)=goto_tab:\(binding.tabIndex)", 125 + "--keybind=ctrl+\(binding.physical)=goto_tab:\(binding.tabIndex)", 126 + ] 127 + } 128 + 129 + static var ghosttyCLIKeybindArguments: [String] { 130 + all.map(\.ghosttyUnbindArgument) + tabSelectionGhosttyKeybindArguments 131 + } 132 + 98 133 static let all: [AppShortcut] = [ 99 134 newWorktree, 100 135 openSettings,
+2 -2
supacode/App/supacodeApp.swift
··· 19 19 var args: [UnsafeMutablePointer<CChar>?] = [] 20 20 let executable = CommandLine.arguments.first ?? "supacode" 21 21 args.append(strdup(executable)) 22 - for shortcut in AppShortcuts.all { 23 - args.append(strdup("--keybind=\(shortcut.ghosttyKeybind)=unbind")) 22 + for keybindArgument in AppShortcuts.ghosttyCLIKeybindArguments { 23 + args.append(strdup(keybindArgument)) 24 24 } 25 25 args.append(nil) 26 26 return args
+60
supacodeTests/AppShortcutsTests.swift
··· 1 1 import CustomDump 2 + import SwiftUI 2 3 import Testing 3 4 4 5 @testable import supacode ··· 14 15 15 16 for shortcut in shortcuts { 16 17 expectNoDifference(shortcut.displaySymbols.joined(), shortcut.display) 18 + } 19 + } 20 + 21 + @Test func worktreeSelectionUsesCommandNumberShortcuts() { 22 + expectNoDifference( 23 + AppShortcuts.worktreeSelection.map(\.display), 24 + ["⌘1", "⌘2", "⌘3", "⌘4", "⌘5", "⌘6", "⌘7", "⌘8", "⌘9", "⌘0"] 25 + ) 26 + 27 + for shortcut in AppShortcuts.worktreeSelection { 28 + #expect(shortcut.modifiers == .command) 29 + } 30 + } 31 + 32 + @Test func tabSelectionGhosttyKeybindArgumentsMatchExpected() { 33 + expectNoDifference( 34 + AppShortcuts.tabSelectionGhosttyKeybindArguments, 35 + [ 36 + "--keybind=ctrl+1=goto_tab:1", 37 + "--keybind=ctrl+digit_1=goto_tab:1", 38 + "--keybind=ctrl+2=goto_tab:2", 39 + "--keybind=ctrl+digit_2=goto_tab:2", 40 + "--keybind=ctrl+3=goto_tab:3", 41 + "--keybind=ctrl+digit_3=goto_tab:3", 42 + "--keybind=ctrl+4=goto_tab:4", 43 + "--keybind=ctrl+digit_4=goto_tab:4", 44 + "--keybind=ctrl+5=goto_tab:5", 45 + "--keybind=ctrl+digit_5=goto_tab:5", 46 + "--keybind=ctrl+6=goto_tab:6", 47 + "--keybind=ctrl+digit_6=goto_tab:6", 48 + "--keybind=ctrl+7=goto_tab:7", 49 + "--keybind=ctrl+digit_7=goto_tab:7", 50 + "--keybind=ctrl+8=goto_tab:8", 51 + "--keybind=ctrl+digit_8=goto_tab:8", 52 + "--keybind=ctrl+9=goto_tab:9", 53 + "--keybind=ctrl+digit_9=goto_tab:9", 54 + "--keybind=ctrl+0=goto_tab:10", 55 + "--keybind=ctrl+digit_0=goto_tab:10", 56 + ] 57 + ) 58 + } 59 + 60 + @Test func ghosttyCLIArgumentsKeepWorktreeUnbindsAndTabBinds() { 61 + let arguments = AppShortcuts.ghosttyCLIKeybindArguments 62 + 63 + for shortcut in AppShortcuts.worktreeSelection { 64 + #expect(arguments.contains(shortcut.ghosttyUnbindArgument)) 65 + } 66 + 67 + for argument in AppShortcuts.tabSelectionGhosttyKeybindArguments { 68 + #expect(arguments.contains(argument)) 69 + } 70 + 71 + for argument in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].map({ "--keybind=ctrl+\($0)=unbind" }) { 72 + #expect(arguments.contains(argument) == false) 73 + } 74 + 75 + for argument in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].map({ "--keybind=ctrl+digit_\($0)=unbind" }) { 76 + #expect(arguments.contains(argument) == false) 17 77 } 18 78 } 19 79 }